Kabir Nigam Kabir Nigam - 27 days ago 7
React JSX Question

How to pass object to hashHistory.push() in react

Anyone know how to pass an object to hashHistory.push()?

Here's a code snippet:

redirectToDrug(id, drug) {
hashHistory.push(`/infusions/library/${id}`, drug);

Trying to get the drug information in there so that I dont have to query the database again for the drug info, as I already have it in the parent class.


You can pass object with query to push function:

  pathname: `/infusions/library/${id}`,
  query: { drug }

And then to access your object in /infusuons/library/${id} page:


Link to official docs

It is good solution if your object isn't too complex, but if drug is a big structure of data, I'd use unidirectional data flow framework, for example Redux.