Home > Software engineering >  TS error Object literal may only specify known properties, and 'state' does not exist in t
TS error Object literal may only specify known properties, and 'state' does not exist in t

Time:03-07

I'm trying to pass props through react router link. Its basically all the user props. This is my code thats getting the error where state: {...employee} is highlighted. I'm really noob when it comes to typescript, trying to get better at it but I'm running into all sorts of problems. When i try to add anything to the state, i still get the same error.

 <Link to={{ pathname: `/edit-employee/${id}`, state: {...employee} }}>

CodePudding user response:

This code would be fine in react-router 5, but you appear to be using react-router 6. In version 6, they split state into its own prop, so you would now do:

<Link to={`/edit-employee/${id}`} state={{...employee}}>
  • Related