在组件聚焦之前不会调用 componentWillReceiveProps,这是我做过的事情吗?

componentWillReceiveProps isn't called until component is focused, is it something I've done?

我正在开发一个 ReactJS 组件,它需要从 URL 获取一些信息。为此,我一直在使用 componentWillReceiveProps 生命周期方法来查看 props.location.query 并将操作分派给 Redux 存储以更新已知状态。我 运行 遇到的问题是 componentWillReceiveProps 似乎没有为我的组件调用,直到该组件具有焦点。我可以重新加载托管此组件的页面并调用渲染,但从未首先调用 componentWillReceiveProps

很明显,我对 componentWillReceiveProps 的生命周期理解不正确,或者我的组件或应用程序中存在其他错误,导致其行为与预期不同.无论哪种方式,请让我直截了当。

componentWillReceiveProps 不会在第一次渲染时被调用。

来自React Docs

"Invoked when a component is receiving new props. This method is not called for the initial render."