For the li tab of dynamic rendering in react, click to switch styles.

as shown below, li is rendered dynamically, and I want to click on it when the background of each li tag turns red. At first, I wanted to add styles by controlling active"s true or false, but this didn"t work. Why clipboard.png

Apr.01,2021

because your li is rendered dynamically, you need to render the click event after rendering. Before li rendering, your click event has already been executed, and you have not added


to your li.

find the problem, go straight to the above picture

clipboard.png
clipboard.png

Menu