您好我有两个反应组件parent
和child
它们都连接到redux
store
到同一个对象,并且该对象从服务器{{1获取数据}}
问题:接收新道具父母asynchronously
被执行但是孩子componentWillReceiveProps
没有执行
任何想法?
子组件
componentWillReceiveProps
当我点击import React, {Component} from 'react';
import {bindActionCreators} from 'redux';
import {connect} from 'react-redux';
class Child extends Component{
constructor(props) {
super(props);
this.handleUserClick = this.handleUserClick.bind(this)
}
handleUserClick(event){
event.preventDefault();
let userInfo = {
email: 'someEmail@gmail.com',
password: 'password',
};
this.props.someAction(userInfo); // changes the store but on store change componentWillReceiveProps not executing
}
componentWillReceiveProps(nextProps){
console.log(nextProps)
}
render(){
return (
<div><form onSubmit={this.handleUserClick}></form></div>
)
}
}
function matchDispatchToProps(dispatch) {
return bindActionCreators(
{ someAction: someAction}, dispatch)
}
function mapStateToProps (state){
return {
dummyState: state.dummyState
};
}
export default connect(mapStateToProps, matchDispatchToProps)(Child);
时会执行但是从服务器handleUserClick
child
接收数据时没有执行,但componentWillReceiveProps
parent
正在执行
我的父组件
componentWillReceiveProps
答案 0 :(得分:3)
如果是第一次渲染子项(将=arrayformula(
if (C1225:C$1684="A",{A1225:A$1684, transpose(split(rept(", ", 460), ",", TRUE))},
if (C1225:C$11="B",{B1225:B$1684, transpose(split(rept(", ", 460), ",", TRUE))},
if (C1225:C$11="AB",{A1225:A$1684, B2:B$11},))))
设置为renderChild
),则不会调用true
(这是用于更新)。你应该改为componentWillReceiveProps
。
如果您将componentWillMount
状态设置为renderChild
已经true
,则不会发生任何事情。
答案 1 :(得分:0)
可能有几个原因
如果您提供了更多src代码,例如您的action creator,reducer和更多源代码,那么它将更容易调试。