0

I'm trying to pass an Object variable trough params with react router v6.

edit:

I don't want to pass all the properties in the navigate, because my data is a super long object. So I want to pass the whole object and extract it's properits in the other component.

The problem is, that the object which was received from the transfer looks like: [object object], and I can't get access to the fields inside of it.

Here is the code in the component when I pass the data with navigate:

    navigate(`/submit-page/${data}`, { replace: true });

And this is the code in the component that recives the data:

import { useParams } from "react-router-dom";

const SubmitPage = () => {
  const params = useParams();

  console.log(params.data); //this prints: "[Object Object]"

  return (
    <>
      <h3>Your data: {params.data.*someField*}</h3> // nothing showing.          
    </>
  );
};
export default SubmitPage;

However, if in the navigate I will send a specific field from the data object, it returns it perfectly.

So the problem is that it can't extract from the params object in the second component.

Can you please help me solve this?

Tehila
  • 917
  • 4
  • 19

0 Answers0