React Native Change State With Unexpected Logging
For context, I am working on this React Native Tutorial The way this logs confuses me. The following is the console output when I changed an empty input field by typing 'a' then 'b
Solution 1:
setState
can be an asynchronous operation, not synchronous. This means that updates to state could be batched together and not done immediately in order to get a performance boost. If you really need to do something after state has been truly updated, there's a callback parameter:
this.setState({ searchString: event.nativeEvent.text }, function(newState) {
console.log('Changed State');
console.log('searchString = ' + this.state.searchString);
}.bind(this));
You can read more on setState
in the documentation.
https://facebook.github.io/react/docs/component-api.html
Post a Comment for "React Native Change State With Unexpected Logging"