Categories

Jul 2, 2019 in React JS

Q:

What is the purpose of callback function as an argument of setState()?

1 Answer

Jul 2, 2019

The callback function is invoked when setState finished and the component gets rendered. Since setState() is asynchronous the callback function is used for any post action.

Note: It is recommended to use lifecycle method rather than this callback function.

setState({ SurName: 'Venkat' }, () => console.log('The Sur name has been updated and component re-rendered'))
Click here to read more about React JS
Click here to read more about Insurance

Related questions

Madanswer
Jul 2, 2019 in React JS
Jul 2, 2019 in React JS
Jul 2, 2019 in React JS
...