React Cookbook
上QQ阅读APP看书,第一时间看更新

How it works...

With componentDidMount, we avoided the infinite loop. The reason why this is a better approach is that componentDidMount is being executed just once when the component is already mounted, and in that method, we are executing our setTimeout and updating the name state only once. In the following recipes, we are going to learn more about React lifecycle methods.