État de passage dans le lien react

import { useNavigate } from "react-router-dom";
const history = useNavigate();

history('/send-message', {state: 'data'});


import { useLocation } from "react-router-dom";
const location = useLocation();

console.log(location.state);
Niraj Kafle