Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

The optimal method of ensuring a function is executed only after setState has fully updated the state is to pass a callback function to the setState method as its second argument. This callback function will be executed only after the state has been updated. For example:

this.setState({ 
  name: 'John' 
}, () => {
  console.log('State has been updated');
  // Call your function here.
});