Skip to content
Advertisement

Change table row color by dynamically updating the className

I created this Typescript class in an attempt to change the row color in a table. My aim was to dyanmically update the className for the tr. Everything displays as expected but nothing happend when I check/uncheck the box. How do I fix this?

JavaScript
JavaScript

Advertisement

Answer

You want to use the React hook useState() inside a React component. (https://reactjs.org/docs/hooks-reference.html#usestate) When state changes, the re-render will update your row class as expected.

JavaScript
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement