I'm trying to send props to a child component rendered with the <Link>
tag from react router. I'm doing like this:
Link
element in the parent component (wrapped with the useRouter
hook, though no idea if I have to):[...]
<Link
to={{
pathname: `/Element/${id}`,
state: {
info: "foo",
},
}}
>
{title}
</Link>;
[...]
import { useLocation } from "react-router-dom";
const Element = () => {
const data = useLocation();
console.log(data)
return (...);
};
This is returning an object with the key state: undefined
What am I missing here? Thanks in advance
I finally found it, I needed to wrap both components with the withRouter
hook