0

I am new to reactjs/nextjs and need some help on how to pass a value from one page to another

I want to pass a value in my "Apply.jsx" page to confirmation.jsx page. The value is "name=joe"

Apply.jsx

Router.push({
            pathname: "/jobseeker/confirmation" })

confirmation.jsx. (need to get value in this function)

  const Confirmation = props => {
      const { children, classes, view, ...rest } = props;
    
      return (
        <div className="cd-section" {...rest}>
          <CardWithoutImg bold view="Seeker" link="confirm" orientation="left" />
        </div>
      );
    };

export default withStyles(blogsStyle)(Confirmation);

1 Answer 1

1

You can pass it as query

const handler = () => {
  Router.push({
    pathname: '/jobseeker/confirmation',
    query: { name: 'joe' },
  })
}

And in Confirmation you can retrieve it using useRouter hook

const Confirmation = props => {
  const router = useRouter();
  console.log(router.query) // { name : 'joe' }
  const { children, classes, view, ...rest } = props;
  ....
};
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.