const location = useLocation(); const navigate = useNavigate(); const state = location.state; // Do some stuff with the state // ... // Clear the state after navigate(location.pathname, { replace: true });