Sutariya Jil
Sutariya Jil

Reputation: 1

how to use history.push() in React-router-dom version 6.0.0

add the history in top of the code like `import {history} form react-router-dom

history.push({
   pathname:"/users",
   state:{
   Key : response.data.user }
});

Upvotes: 0

Views: 966

Answers (1)

Quentin
Quentin

Reputation: 944455

See the upgrade guide in the documentation.

Use useNavigate instead of useHistory

let navigate = useNavigate();
const someFunction = () => {
     const options = {
         state: { 
             Key: response.data.use
         }
     }
     navigate("/users", options);
}

Upvotes: 2

Related Questions