[英]componentWillReceiveProps isn't called until component is focused, is it something I've done?
I have a ReactJS component that I'm developing which needs to get some information from the URL. 我有一个正在开发的ReactJS组件,需要从URL获取一些信息。 To do this I've been utilizing the componentWillReceiveProps lifecycle method to look at props.location.query and dispatches actions to a Redux store in order to update the known state. 为此,我一直在使用componentWillReceiveProps生命周期方法来查看props.location.query并将操作分派到Redux存储以更新已知状态。 The problem that I'm running into is that it doesn't appear that componentWillReceiveProps is being called for my component until that component has focus. 我快到的问题是,它不会出现componentWillReceiveProps被称为我的组件,直至组件具有焦点。 I can reload the page which hosts this component and the render is called but componentWillReceiveProps is never called first. 我可以重新加载承载此组件的页面,并调用渲染器,但永远不要首先调用componentWillReceiveProps 。
Clearly I'm either understanding the lifecycle incorrectly with respect to componentWillReceiveProps or there is something else either wrong in my component or application which is make it behave differently than it is intended. 显然,我或者相对于componentWillReceiveProps不正确地理解了生命周期,或者我的组件或应用程序中存在其他错误,这使得它的行为与预期不同。 Please set me straight either way. 不管怎样,请让我挺直。
componentWillReceiveProps isn't called on the first render. 在第一个渲染上未调用componentWillReceiveProps。
From the React Docs : 从React Docs :
"Invoked when a component is receiving new props. This method is not called for the initial render." “在组件接收新道具时调用。初始渲染未调用此方法。”
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.