In a list component I have passed data via Link
, like so
playListState.map((list) => {
return (
<>
<Link
to={`/playlists/${list.id}`}
state={{ from: list }}
key={list.id}
>
<p>{list.title}</p>
</Link>
Then in the component that I want to use the props from the data that I passed.
I try to get them via useLocation
like so,
const location = useLocation();
const { title, songs, } = location.state as PlayList;
console.log(location.state, "location");
PlayList
are the props of the data I am passing.
In the log I see the state that I am passing but
when I log title it's undefined. I have looked online and
tried to implement a few things, but without success. So how can I get the data that a passed and display it in my component?