I need to pass the id to a different component.
import { Link } from "react-router-dom";
const Option = () => {
return (
<section className="section">
<Link
to={{
pathname: "/person",
state: { id: "12345" },
}}
>
<button class="button is-primary">Click Me</button>
</Link>
</section>
);
};
export default Option;
The component where I am accessing the id
const Person = (props) => {
let data = useLocation();
console.log(data);
return (
<section className="section has-text-centered mt-4">
<h1>Hello</h1>
</section>
);
};
export default Person;
But I am getting state as undefined. How do I access the id that I have passed in ?