I'm trying to pass state from one page to another and am running into problems.
Page 1
<Link to={'/events'} state={{ id: "Check" }}>
Check
</Link>
Page 2 - Events
export class Events extends Component {
render() {
return (
<div>
<h1>Events Page</h1>
</div>
);
}
}
export default function page(props) {
const location = useLocation();
return (
<div>
<h1>{this.props.location.state.id}</h1>
</div>
);
}
I'm getting the following errors:
React Hook "useLocation" is called in function "page" that is neither a React function component nor a custom React Hook function.
Parameter 'props' implicitly has an 'any' type.
45 | export default function page(props) {
'this' implicitly has type 'any' because it does not have a type annotation.
49 | {this.props.location.state.id}
I've tried multiple methods and I am struggling to get anything to compile. I'm very new to React and I am just missing something. There seems to be a difference between V5 and V6 react-router
which is tripping me up (Using V6).