Javascript Redux商店没有';t随反应状态的变化而变化
我正在尝试根据当前状态更改更改redux存储,状态正确更改,但Javascript Redux商店没有';t随反应状态的变化而变化,javascript,reactjs,redux,react-redux,redux-thunk,Javascript,Reactjs,Redux,React Redux,Redux Thunk,我正在尝试根据当前状态更改更改redux存储,状态正确更改,但this.props仍作为初始化。这是我的密码: componentWillMount(){ this.props.fetchMatches(); } handleChange(newDateRange){ console.log('===================================='); console.log('handleChange fired'); consol
this.props
仍作为初始化。这是我的密码:
componentWillMount(){
this.props.fetchMatches();
}
handleChange(newDateRange){
console.log('====================================');
console.log('handleChange fired');
console.log(this.state);
console.log('====================================');
}
function mapDispatchToProps(dispatch) {
return {
handleChange: (newDateRange) =>
dispatch({
...this.props.home,
startDate: newDateRange[0],
endDate: newDateRange[1]
})
}
}
export default connect(mapStateToProps, { mapDispatchToProps, fetchMatches })(Home);
下面是DateRange
的实现:
<DateRangeInput className="daterange" value={[this.props.startDate, this.props.endDate]} onChange={this.handleChange} />
您无法从此访问mapDispatchToProps中的道具,因为即使在安装组件之前也会调用该函数。而是从mapDispatchToProps访问它,它在第二个参数中公开了前面的道具
function mapDispatchToProps(dispatch, ownProps) {
return {
handleChange: (newDateRange) =>
dispatch({
...ownProps.home,
startDate: newDateRange[0],
endDate: newDateRange[1]
})
}
}
您无法从此访问mapDispatchToProps中的道具,因为即使在安装组件之前也会调用该函数。而是从mapDispatchToProps访问它,它在第二个参数中公开了前面的道具
function mapDispatchToProps(dispatch, ownProps) {
return {
handleChange: (newDateRange) =>
dispatch({
...ownProps.home,
startDate: newDateRange[0],
endDate: newDateRange[1]
})
}
}
当我更改
日期范围的值时,这不会运行,如何在调用的handleChange
函数上激发它?您可以共享日期范围实现吗。我还要问一下,为什么connect中的第二个参数是一个对象,而不仅仅是:export default connect(mapstatetops,mapsdispatchtoprops)(Home)
如果将对象作为第二个参数传递给connect(),它会假定您已将道具名称映射给动作创建者,因此它会通过bindActionCreators实用程序自动运行所有道具,并将结果用作道具。目前,react-redux将{mapDispatchToProps,fetchMatches}
作为第二个参数,假设mapDispatchToProps
和fetchMatches
都是动作创建者。选中此复选框当我更改DateRange
的值时,此复选框不会运行,如何在调用的handleChange
函数上触发此复选框?您可以共享DateRange实现吗。我还要问一下,为什么connect中的第二个参数是一个对象,而不仅仅是:export default connect(mapstatetops,mapsdispatchtoprops)(Home)
如果将对象作为第二个参数传递给connect(),它会假定您已将道具名称映射给动作创建者,因此它会通过bindActionCreators实用程序自动运行所有道具,并将结果用作道具。目前,react-redux将{mapDispatchToProps,fetchMatches}
作为第二个参数,假设mapDispatchToProps
和fetchMatches
都是动作创建者。检查此项当我更改DateRange
的值时此项不运行,如何使此项在调用的handleChange
函数上启动?this.props.handleChange([startDate,endDate])
我在这里怎么做?我不知道DateRangeInput
如何工作,你能用handleChange
handleChange:(v)=>console记录结果吗?log(v)不被调用!没有记录任何东西!当我更改DateRange
的值时,它不会运行,我如何使它在调用handleChange
函数时启动?This.props.handleChange([startDate,endDate])
我在这里怎么做?我不知道DateRangeInput
如何工作,你能用handleChange
handleChange:(v)=>console记录结果吗?log(v)不被调用!没有记录任何东西!