componentWillReceiveProps
全部标签 我遵循了https://reactjs.org/blog/2018/03/27/update-on-async-rendering.html#gradual-migration-path中的建议在升级到React16.3.2之后,我想将我们所有即将弃用的生命周期方法重命名为它们的UNSAFE_等价物。但是我注意到UNSAFE_componentWillReceiveProps根本没有被调用。当我将其改回componentWillReceiveProps时,它会起作用。任何想法为什么?classChartextendsReact.Component{chartContainer:SVGS
我有React/Mobx应用程序。当我在商店中进行更改时,组件正在更新(重新渲染),但我需要进行一些比较以添加更多功能,因此我想使用componentWillReceiveProps(nextProps)并将nextProps与this.props进行比较。不知何故,它没有被调用。任何想法,我做错了什么,或者我还能做些什么来获得它? 最佳答案 tl;dr:使用componentWillUpdate和componentDidUpdate作为prop传递的对象Store永远不会改变,即使它的内容发生变化。使用@observable的技巧
我的React应用程序中有一个组件可以为用户呈现总值。当该值上升时,我想发出声音。我认为在显示总数的组件中是播放噪音的好地方。所以我在组件中添加了一个componentWillReceiveProps方法,在其中,我计算了两个总数:total是从this.props计算的nextTotal是根据nextProps计算的。令我惊讶的是,即使值发生变化,总计也发生变化,nextTotal和total始终相同。所以我想在总数上升时开火的条件永远不会发生。我编写了一个简单的单组件示例。JSfiddle.varHello=React.createClass({componentWillRecei
我试图在从子组件更改状态后更新状态但没有成功,每次我调用该函数时都会出现堆栈溢出,prop无限次调用该函数,但问题是,我真的需要更新这个状态,目前不知道如何解决这个问题。父级importReact,{PropTypes,Component}from'react';importCardfrom'./card/card.js';importstylefrom'./style.scss';classContainerextendsComponent{constructor(props){super(props);this.state={isFlipped:false,oneOpened:tr
我有一个像这样呈现的React.js组件:;页面上有一些事件会更新this.state.email,结果会通过render,发送一个新的emailprop到Social组件。在这个Social组件中,我正在监听这样的更新:componentWillReceiveProps:function(nextProps){console.log('receivedpropsupdate',nextProps.email);this.doSomeWork();}该控制台行被渲染两次,这使得用户界面随着对社交网络的调用而闪烁两次。我总是可以做这样的事情:if(nextProps.email!=thi
我将使用redux调用api:我使用了axios,history,react-redux,react-router-native,react-router,,redux-promise-middleware,redux-thunk组件使用redux进行api调用:我创建了Reducers文件夹,并将我所有的reducer文件放在它们自己的文件中,然后将它们合并到一个主文件中,如下所示这是我的generateoptReducer.js文件:constinitialState={data:{},error:null,status:null};import{generateOTP}from'
在我的应用中,有一些阶段和游戏与阶段相对应。我在componentdidmount,然后在componentwillreceiveprops中获取舞台触发了无限的时间。有人可以解释为什么吗?componentDidMount(){this.props.fetchCurrentStage();}componentWillReceiveProps(nextState){if(nextState.stageReducer&&nextState.stageReducer.stageId){this.props.fetchGamesForStage(nextState.stageReducer.stag
这合法吗?componentWillReceiveProps:function(nextProps){if(typeofnextProps.contact!='undefined'){this.setState({forename:nextProps.contact.forename});this.setState({surname:nextProps.contact.surname});this.setState({phone:nextProps.contact.phone});this.setState({email:nextProps.contact.email});}}因为我不
这合法吗?componentWillReceiveProps:function(nextProps){if(typeofnextProps.contact!='undefined'){this.setState({forename:nextProps.contact.forename});this.setState({surname:nextProps.contact.surname});this.setState({phone:nextProps.contact.phone});this.setState({email:nextProps.contact.email});}}因为我不
WhataretypicalusecasesforReactlifecyclemethodslikecomponentWillReceivePropscomponentWillReceiveProps和其他生命周期方法似乎具有欺骗性的诱惑,给没有经验的React编码人员手中的代码带来不必要的复杂性和噪音。它们为什么存在?他们最典型的用例是什么?在不确定的时刻,我怎么知道答案是否在生命周期方法中?我已经使用react几个月了,我的大部分工作都是从头开始创建一个大型应用程序。所以同样的问题一开始就出现了。以下信息基于在开发过程中学习并查阅了多个文档以使其正确。正如问题中所问的,这里是react中生