Click to change the variable in react, why does it not work?

it is clear that the value of the variable has changed, why does the text on the page not change?

Mar.18,2021

this.setState({like: !this.state.like})

setState before render, changes state directly will not render again


after changing the state, it is useless to call the render method. You need to use this sentence:

  

changes to state in react need to use the setState method to ensure that ui and state maintain Synchronize. This is the most basic react common sense-copy~, read more documents

Menu