简体   繁体   English

在组件被聚焦之前,未调用componentWillReceiveProps,这是我做的吗?

[英]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.

相关问题 正则表达式 - 我做错了什么吗? - Regex - is there something I've done wrong? ReactJs:没有为 redux 操作最后调度的组件调用 componentWillReceiveProps - ReactJs: componentWillReceiveProps doesn't get called for component whose redux action gets dispatched last 我的函数中未调用异步Mocha done() - Async Mocha done() isn't called in my function LocalStrategy完成回调期间未调用我的serializeUser - my serializeUser isn't being called during LocalStrategy done callback React-Router v4.2.2无法正常工作(我认为我在Route标签中做错了什么?) - React-Router v4.2.2 not working (I think I've done something wrong in the Route tag?) React / Mobx - 组件正在重新渲染,但未调用componentWillReceiveProps() - React/Mobx - component is re-rendering, but componentWillReceiveProps() is not being called 如何暂停javascript直到完成某事? - How to pause javascript until something is done? 我有一个javascript函数,我无法分辨自己做错了什么 - I have a javascript function, and I can't tell what I've done wrong 未调用componentWillReceiveProps - componentWillReceiveProps not being called React - componentWillReceiveProps 条件不呈现组件中的数据 - React - componentWillReceiveProps condition doesn't render the data in the component
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM