reactjs - 在类组件中多次导出反应问题
问题描述
以前在我的 Class Component redux connect 中看起来像这样。这没有任何问题。
//File: MyComponent.jsx
//in below code this.props.selectProducts is not undefined and this works fine
const mapStateToProps = null;
const mapActionsToProps = {
selectProducts
};
export default connect(
mapStateToProps,
mapActionsToProps
)(MyComponent);
在此之后,我不得不使用这个名为notistack的组件来显示小吃栏,并将其导出为默认值,而不是现有的 redux 连接。现在我面临一个道具不存在的问题。
const mapStateToProps = null;
const mapActionsToProps = {
selectProducts
};
//Now this.props.selectProducts is undefined which is part of redux store
//But this.props.enqueueSnackbar("Preference saved."); this works. which is part of withSnackbar
export const ConnectedList = connect(
mapStateToProps,
mapActionsToProps
)(MyComponent);
export default withSnackbar(MyComponent);
如果我将 redux 设置为默认连接,我将无法访问 this.props.enqueueSnackbar()。任何帮助将非常感激。谢谢
解决方案
只需withSnackbar
在返回的组件上connect
使用并使用它:
const ConnectedList = connect(
mapStateToProps,
mapActionsToProps
)(MyComponent);
export default withSnackbar(ConnectedList);
推荐阅读
- assembly - 为什么 BIOS 需要在第二条指令中将(看似)随机地址中的值与零进行比较?
- jackson - 杰克逊序列化/反序列化多态性多对一使用现有属性
- reactjs - 如何在 react js 中运行 powershell 脚本?
- python - 将新列添加到 python 中的数据框时出现错误“NameError: name 'newaxis' is not defined”
- bash - bash shell 脚本中的 -n 运算符代表什么?
- javascript - 我应该怎么做才能从 API 调用中呈现数组对象值的总和
- c - C - 调试断言失败:_CrtIsValidHeapPointer(block)
- python - 程序未进入嵌套在 while 循环中的 for 循环
- python - 我的代码只循环到某个点,然后忽略 Python,字典
- typescript - 如何从响应中获取中间件上下文?