why is componentWillReceiveProps deprecated?

前端 未结 2 1042
臣服心动
臣服心动 2020-12-08 20:01

I read through https://reactjs.org/blog/2018/03/27/update-on-async-rendering.html#fetching-external-data-when-props-change . I am still not able to understand why did they h

2条回答
  •  不知归路
    2020-12-08 20:39

    My understanding is that if the componentWillReceiveProps() method is being invoked then some properties of the component has been changed and that component should be informed and potentially re-rendered again.

    Having ajax call inside of the componentWillReceiveProps() might break that flow.

    My gut feeling is that we are gently guided to make ajax calls outside of the components and pass all the results of those ajax calls through properties. It makes your components very clean and testable.

提交回复
热议问题