reactjs - this.props 在组件 ReactJS 的第一次调度操作后变得未定义
问题描述
我在我的反应组件中使用第三方组件,并且我正在使用 redux 流进行状态管理。
客户组件
class Customer extends React.Component {
constructor(props) {
super(props); //This works fine and props are correct
}
render() {
return (
<>
<div>Hello</div>
<ThirdPartyComponent
eventHandlers={
new Map([
[
"loaded",
function () {
//This is the second action call but this.props becomes undefined at this stage after
//the first action of getCustomerObject is called. Not sure why? This is the problem
this.props.actions.handleExtraFunctionality();
},
],
getCustomer={(customerObject) => {
//This is the first action call and it works which updates the state
this.props.actions.getCustomerObject(customerObject);
}}
/>
</>
);
}
function mapStateToProps(state) {
return state;
}
function mapDispatchToProps(dispatch) {
return {
actions: {
handleExtraFunctionality: bindActionCreators(
customerActions.handleExtraFunctionality,
dispatch
),
getCustomerObject: bindActionCreators(
customerActions.getCustomerObject,
dispatch
),
},
};
}
export default connect(mapStateToProps, mapDispatchToProps)(Customer);
行动
function getCustomer(customer) {
return { type: types.GET_CUSTOMER, customer};
}
我试图在第一个动作之后调用第二个动作,但是 this.props 在第一个调用完成后变得未定义。我不确定为什么?有人可以帮忙吗?
解决方案
推荐阅读
- sql - 如何将小数点前后的值存储在 2 个不同的列中
- c# - blazor 中的 OnInitializedAsync()
- python - Python生命线包中Cox比例危险法和Weibull AFT模型的区别
- powershell - 通过windows任务调度程序将参数传递给powershell脚本不起作用
- ios - 如何从“使用 Apple 登录”验证 identityToken?
- javascript - :host 被通用选择器 css 覆盖
- google-app-engine - 我如何知道 Google App Engine 实例是标准的还是灵活的?
- linux-kernel - Binder中的双向链表task_list为什么是空的?怎么打印?
- javascript - 按首字母 JavaScript 分组的问题
- c# - 使用 Sage50 Canada 2019 的示例 sdk 代码创建销售发票时出现异常错误