score:17
Accepted answer
you can pass it by mentioning the props in state
<link
to={{
pathname: "/invoicedetails",
state: { name: 'jack', age: 25, city: 'antwerp'}
}}
/>
read about it more here
and to use it in your next component you have to either wrap your component with a react-router-dom hoc withrouter
or use uselocation
hook they have provided.
ex- in your second component -
import {uselocation} from "react-router-dom";
function child() {
let data = uselocation();
console.log(data); //state would be in data.state//
}
Source: stackoverflow.com
Related Query
- how to pass props to the route when using react router <Link>
- How to pass the match when using render in Route component from react router (v4)
- How do you pass data when using the navigate function in react router v6
- I can not get the state from react router Link component using useLocation. So how can I pass it?
- How to pass props using react router link v6?
- How to pass a prop from one component to another when using react router link
- How can I pass props from one component to another using Link and router in react
- React - How to pass props down for the .map function when using functional components
- React Router render error when using Link inside the Route element
- Can't figure out how to pass props to components when using React Router v5 and Redux
- How to pass params into link using React router v6?
- How to create a preview (Image and description) to the Url when shared link on Social media,Gmail and Skype using React JS?
- React Hook Forms How to pass the errors as a props using Typescript
- How to pass props to route components when using useRoutes?
- How to Handle Redirecting to the Same Route (with Query Params) Using React Router v4
- How to pass props to route in react router v5 with Typescript?
- How to link to Routes inside the component rendered by another Route with React Router
- can't pass props using Link in react router dom
- How can I pass function using props in React Router Link?
- Using react router, how can I pass component props using a route config?
- How do you catch incorrect location pathnames in React Router when using the <Router> component?
- React - how to add boolean field on props when using map(), given that the field will be changing
- react router - passing props using route deletes all the other props values
- I'm using router for the first time.. How can I make route to render first component automatically when it's opened?
- Im using React Router and I want one of my route links with path="/" to be the home page on reload.. How can you do that?
- Props that is being passed into React Route is undefined for the first render when using useEffect
- How to pass props inside of Router while using React Context
- How to pass props/params/state to a Route with Link in React Router 5.2.0?
- How do I use react context API to pass data from parent component to child component when using react-router in the parent component in React.js?
- how to pass parameters to component using react route link
More Query from same tag
- ReactJS breaks code after being imported on Symfony project
- React Native: this.setState is not a function
- How do I add trusted certificate to my React Project.?
- ipcRenderer in React component constructor
- plyr-react ref.current.plyr.on is not a function
- Send request depending on a condition from a previous request
- Structured Data for SEO using Gatsby or a SPA
- How to write arrow function in a normal function
- How to output an array in Javascript like a social media feed?
- React, using .map with index
- How to make a npm package from Create React App /build folder?
- Elements not processing event when Material-ui Popup is displayed
- Iteration over FileList, React, Typescript
- Filter API Object Array by Matching Object Properties
- Objects are not valid as a React child with Styled components
- React Render Called Twice, Props Undefined on Second
- Webpack build for application with core and sub modules
- Webpack error: You may need an appropriate loader to handle this file type
- Inline map statement React
- React - Mutating the state argument from setSate
- How make unit test with react apollo component?
- access clicking edit icon in material table
- How to deploy React with Laravel to my development server
- How can I assign a new ref to every iteration inside a map function?
- Semantic-UI container gets margins automatically at certain breakpoints
- InputText component results in TypeError: e.target is null when typing into text box (PrimeReact library, using arrow function)
- use create-react-app with php index
- How I can create a simple React component rendered as a <div> which takes a text value and a foreground color as input
- Getting duplicate button when mapping
- Can't accees to redux store (basic redux example)