javascript - ajax at didMount or willMount
天蓬老师
天蓬老师 2017-07-05 11:07:35
0
1
1145


After looking at the breakpoints, the order is 16-30-21-30. That is, after willmount, the asynchronous method render and load are executed in the task queue, setState, diff, then render
Why do they say ajax is required in didmount

天蓬老师
天蓬老师

欢迎选择我的课程,让我们一起见证您的进步~~

reply all(1)
伊谢尔伦

Whether an asynchronous request is triggered in willMounnt or didMount, it will be rendered twice. The first time is when the component is loaded, and the second time is when the asynchronous request returns setState.

However, the logic should be to display the component, such as the loading status, and then trigger the request. Another most important point is that after react fiber is updated, it will trigger willMounnt multiple times, which will cause bugs. Therefore, asynchronous requests are generally placed on didMount.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template