我想做的是:a,b,c三个组件用react-redux进行数据管理,但是我现在遇到的问题是:b通过属性赋值,c通过props收到a的值,但是b的state值改变,c却不会变化了,很奇怪 handleSearch(value) { this.state.historyList.push(value) this.setState({
historyList: this.state.historyList //1
})
}
render() { return (
<Fragment>
<SearchHeader toSubmit={this.handleSearch}/>
<SearchContent historyList={this.state.historyList} /> //2
</Fragment>
)
}如代码所示:原本this.state.historyList可以用通过属性传值给子组件SearchContent .实现中间组件state的状态改变,进行子组件的render函数再次调用刷新数据;
但我发现:export default connect(mapStateToProps, mapDispatchToProps)(SearchContent)把子组件用connect连接了,
最后中间组件的this.state.historyList改变,子组件没触发render函数的调用,
但是改为export default SearchContent这样能收到新的数据
哪里写错了吗?
互换的青春
相关分类