history.push not working open in new tab in react

I am new to react js and I am a self-learner. I need to pass some data with my react route and access this data on another side...So I used useHistory() hook to accomplish my task. But now I have some errors. I can only route with mouse click event only. I can't route using open in new tab or my mouse wheel. I have no idea what's going on with my code. So Anyone can help me with that...Thank you.

  const sendPixelData = () => {
      pathname: `product/${product._id}`,
      state: { detail: product },

 <Link onClick={sendPixelData}> Do some logic and other thing  </Link>

1 answer

  • answered 2022-01-25 10:06 Ivo

    A Link component from react-router should not have an onClick parameter but follow the props needed according to the documentation:


    If you want to pass data you can use the following syntax:

      pathname: `product/${product._id}`,
      state: { detail: product },

How many English words
do you know?
Test your English vocabulary size, and measure
how many words do you know
Online Test
Powered by Examplum