React 在哪个生命周期里监听props变化发请求

先说答案 (第三个参数 是 getSnapShotbeforeUpdate 的返回值)

componentDidUpdate(prevProps, prevState, snapshot)

Use this as an opportunity to operate on the DOM when the component has been updated. This is also a good place to do network requests as long as you compare the current props to previous props (e.g. a network request may not be necessary if the props have not changed).

上面文档翻译一下大概意思就是 可以 在componentDidUpdate()里面 操作dom, 也是一个合适的

位置用来发请求 当你 比较了当前的 props 和 前一个 props

还是推荐大家看 英文文档

https://reactjs.org/docs/react-component.html#getsnapshotbeforeupdate

你可能感兴趣的:(#,React,react.js,javascript)