Home > database >  React V6 - How to pass an object from a class component to another (and not to functional component)
React V6 - How to pass an object from a class component to another (and not to functional component)

Time:08-13

I am trying to pass an object to a class component via the router. The browser doesn't display any error, but I don't know how reach the object It's worked when I user the v5, but not with the v6 All the answers available on the subject are for the case you use functional component

<Link to={`myPath`} state={{ myObject }}>
....
</Link>

Thank you

CodePudding user response:

The way you are passing the state object is incorrect. Please try like this

<Link
  to={{
    pathname: "/myPath",
    state: myObject
  }}
/>
....
</Link>

for more information refer :

https://v5.reactrouter.com/web/api/Link

  • Related