score:8
Accepted answer
in react-router-dom
v6 the link
component api changed a bit, route state is now a top-level prop instead of being nested in a to
prop's object.
interface linkprops extends omit< react.anchorhtmlattributes<htmlanchorelement>, "href" > { replace?: boolean; state?: any; to: to; reloaddocument?: boolean; }
move the nested state
property out to be a link state
prop.
<link
to={`/quiz/${video.youtubeid}`}
state={{ videotitle: video.title }} // <-- state prop
key={video.youtubeid}
>
<video
title={video.title}
id={video.youtubeid}
noq={video.noq}
/>
</link>
you also are not accessing the location
object correctly, the uselocation
hook returns a location
object, not an object with a location
property.
const location = uselocation();
const { state } = location;
or destructure state
directly
const { state } = uselocation();
score:0
const { location } = uselocation();
to
const location = uselocation();
const { state } = location;
or
const { state }= uselocation();
just destructure error
Source: stackoverflow.com
Related Query
- I can not get the state from react router Link component using useLocation. So how can I pass it?
- Styling the active link using the NavLink component from React Router is not working as expected
- Can not able to get the location state when opened with "open link in a new tab" in react router
- Why does not the background color get applied from props using state for a styled component div using react and typescript?
- React Router Link is not working. The Route changes but the component doesn't get rendered
- How can I pass props from one component to another using Link and router in react
- React component using fetch not populating the state from response
- How to pass the match when using render in Route component from react router (v4)
- How do I manage state on a React component that can have state changed from the parent or from events upon it?
- Why can I not get a reference to my component from the ReactDOM.render() callback?
- React Router "Link to" does not load new data when called from inside the same component
- React router dom passing data from parent component to child router component does not pass the props.match
- How to update redux state using a react variable passed up to the component from a child
- React reach router link tag updates url but not the component
- react router not rendering the component when using redux
- I want to navigate to a page/component where I passed the data from another component using both React hooks and useHistory, but I get undefined
- How do I stop state store data from accumulating in a redux component every time I navigate to it using react router
- update react child component's state using props received from an async api call made in the parent component
- How can I get the jsessionid from a response using react js?
- React Router v6 Link component not changing the page at root url
- Able to get the updated state from redux store but not able to access the objects inside the updated state from the receiver component
- Reactjs - changing url using react router but the component does not change
- How to pass a prop from one component to another when using react router link
- How can I get the correct current path in React using react router 4.2.2's withRouter?
- Can I get a reference to jsx react component so I can I forceUpdate/rerender react component from the chrome developer console?
- External link not working when using LINK from react router dom
- React Child component not sent the updated state from parent
- how to get route param values of child component from parent component in app using React Router
- React router 4 - Why is my component only rendered on manually setting the url but not on clicking a Link with same url?
- How can I set the state of my parent component from the child component when using react-router?
More Query from same tag
- reactjs + webpack + babel 7 Syntax error: The rest element has to be the last element when destructing
- How to conditionally render a prop in TSX
- Pass additional props to a react component
- React form refreshes the entire page onSubmit and setState not working
- Add style to array element from another object array
- How to implement Razorpay payment button in next.js page
- How to render single react component with different data?
- Need to add a simple functionality to a simple calculator made in React JS
- uploading xlsx or csv files to firebase
- Assistance in having create post button / send message buttons not be visible to users who aren't logged in
- Multi layout react routing with 404 component and without re-rendering layout on URL change
- Office.js | Excell add in | get selected cell address on click
- What does the double ampersand selector '&&' do (overriding root class using makeStyles in Material-UI React)?
- What is meaning of symbol &tagname: for css styling in material UI. Ex: &div: { display: 'flex' '}
- Why is my websocket listener only firing one time when declared in useEffect with empty array as the second argument?
- Issue with setting State with setInterval and clearInterval
- How to update google-maps-react direction route?
- TypeScript React - useReducer with Array of Objects in Interface
- Spread operator in react is causing each character to be saved in it's own array, when updating in firebase
- Material-UI Menu component only last MenuItem onClick action is triggered
- How to handle selection in reactstrap drop down list
- Upgrade to Webpack 5 failing
- Autocomplete hover not responding properly
- springboot for backend reactjs frontend
- Understanding how to have multiple pages with React and react-router
- how to make a custom hook being executed once globally
- React Material UI Dropdown Menu Icon
- How to display all options in one line using antd Select component?
- Static methods in React
- React props - set isRequired on a prop if another prop is null / empty