Sometimes, we want to fix onClick can’t pass value to method with React.
In this article, we’ll look at how to fix onClick can’t pass value to method with React.
How to fix onClick can’t pass value to method with React?
To fix onClick can’t pass value to method with React, we set the onClick
prop to a function that calls a function that takes the value we want.
For instance, we write
<th value={column} onClick={() => handleSort(column)}>
{column}
</th>
to set the onClick
prop to a function that calls handleSort
with the column
variable.
The function is called when we click on the th element.
Conclusion
To fix onClick can’t pass value to method with React, we set the onClick
prop to a function that calls a function that takes the value we want.