I need to change state by clicking. I have this code:
var Component = React.createClass({ getInitialState : function() { return {value : 0} } changeState : function(event) { this.setState({value : event.target.id}) ; } render : function() { <a id="1" onClick={this.changeState}>Change</a> } }) ; But the change only works after the first click, the first click I get 0 , the second click, I get 1 .
I reread the dock where it is said not to use setState directly, so I used replaceState , but it still returns the previous value. How to deal with it?
returnthere is noreturn. And I propose to add a viable snippet to the question. And yet, I didn’t see a recommendation in the dock not to usesetState- you definitely don’t confuse with a recommendation not to usestatefor writing? - Qwertiy ♦