Categories
React Answers

How to fix onClick can’t pass value to method with React?

Spread the love

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.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *