How to send params in useHistory of React Router Dom?

Kais picture Kais · Dec 24, 2019 · Viewed 9k times · Source

I am using React Router hooks for navigation useHistory.

Navigate : history.push("/home", { update: true });

In home : I am trying to get params let {update} = useParams();

But update is always undefined. Whats wrong with this code. Any suggestions ?

Answer

Vahid Akhtar picture Vahid Akhtar · Dec 24, 2019

This is how you can pass

history.push("/home", { update: true });

and access like this if it's stateless component.

props.location.state.update;

if class based component.

this.props.location.update;