Advertisements
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 = () => {
history.push({
pathname: `product/${product._id}`,
state: { detail: product },
});
};
<Link onClick={sendPixelData}> Do some logic and other thing </Link>
>Solution :
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:
<Link
to={{
pathname: `product/${product._id}`,
state: { detail: product },
}}
/>