#How to send props to another component using a router
5 messages · Page 1 of 1 (latest)
Not sure what you mean here but usually you pass props to another component either from a parent to a child, or using the useContext hook
you can use the render method of the Route component from the react-router-dom library. The render method allows you to pass props to the component that the Route is rendering.
As far as I know this is not needed anymore in react v6 if you pass your component to the new Route element's element property.🤔
@steep wharf , router is not used to propagate state within your application, it's pure function is client side routing.
The only thing you could do is to read out the parameters from the url and use those values. You can redirect the user from 1 page to another with some parameters in the url, which can be used on another page. The values should kept to the bare minimum imo otherwise your url can get very messy very easily.
If you need to share state between different part of your application and doing so is very difficult, you can do what @wise walrus mentioned and use react's context provider or some other state manager library eg.: jotun, zustand, redux
Thanks for ur responses @storm kayak ce @native egret @wise walrus . I've shared state in this way. polldata is the state i need to transfer to dashboard component.. it's worked <Link to="/dashboard" state={{ pollData: pollData }}>
<button id="create-poll-btn">Create Poll</button>
</Link>