【发布时间】:2019-01-18 05:14:41
【问题描述】:
我有以下代码可以正常工作
module.exports = injectIntl(redux.connect(mapStateToProps, mapDispatchToProps)(props => {
document.title = props.intl.formatMessage({ id: "app-name" });
return (<App {...props} />);
}));
当我将 mergeProps 添加到 redux.connect 时,'intl' 不再存在于我的 props 中,并且在尝试设置 document.title 时出现错误
损坏的代码:
module.exports = injectIntl(redux.connect(mapStateToProps, mapDispatchToProps, mergeProps)(props => {
document.title = props.intl.formatMessage({ id: "app-name" });
return (<App {...props} />);
}));
我的 mergeProps 函数:
function mergeProps(stateProps, dispatchProps) {
const mergeProps = {
error() {
alert("throw error");
},
};
return Object.assign({}, stateProps, dispatchProps, mergeProps);
}
在redux.connect函数中用null替换mergeProps时,没有报错,代码运行正常。
知道为什么 merge props 似乎破坏了 react-intl 注入吗?
【问题讨论】:
标签: reactjs redux react-redux react-intl