reactjs - 简单的 react-redux 连接函数中的错误
问题描述
尝试使用 react-redux 的“连接”功能时收到以下错误:
"TypeError: react__WEBPACK_IMPORTED_MODULE_4___default.a.memo is not a function"
此外还有以下细节:
wrapWithConnect
C:/.../node_modules/react-redux/es/components/connectAdvanced.js:325
322 | } // If we're in "pure" mode, ensure our wrapper component only re-renders when incoming props have changed.
323 |
324 |
> 325 | var Connect = pure ? React.memo(ConnectFunction) : ConnectFunction;
326 | Connect.WrappedComponent = WrappedComponent;
327 | Connect.displayName = displayName;
328 |
我还没有找到与我的问题相关的这个错误的任何参考......
这是我在“Chat.js”类末尾使用“connect”的代码:
import { connect } from 'react-redux';
...
const mapStateToProps = state => ({
...state
});
const mapDispatchToProps = dispatch => ({
addMessage: () => dispatch(addMessage)
});
export default connect(
mapStateToProps,
mapDispatchToProps
)(Chat);
此代码用于名为“Chat.js”的类中。当使用“导出默认聊天”而不使用 redux“连接”时,一切正常。
我使用提供者标签作为“App.js”中聊天组件的包装器:
import { Provider } from 'react-redux';
const App = class extends React.PureComponent {
render() {
const { title } = this.context;
return (
<div className="center-screen">
{title}
<Provider store={configureStore()}>
<Chatroom />
</Provider>
</div>
);
}
};
行动:
export function addMessage(text) {
return { type: 'addMessage', text };
}
减速器:
export default (state, action) => {
switch (action.type) {
case 'addMessage':
return {
text: action.text
};
default:
return state;
}
};
解决方案
也共享 webpack 文件。这样我就可以检查 webpack 设置中是否有任何问题
推荐阅读
- function - 初学者阅读fortran代码但无法理解这一点
- java - 使用 Apache Phoenix JDBC 驱动程序时如何配置 queueSize 和 ThreadPoolSize?
- sql-server - Sql Server 转换问题?从字符串到日期时间?问题是我没有字符串字段
- swift - 滑动时快速黑屏
- angular - Angular 6:错误错误:找不到具有角度材料和反应形式的未指定名称属性的控件
- python - 在 Cassandra 中只保留最新的 N 行
- java - 使用自定义关键字上传 Katalon 文件
- javascript - 如何快速启动重度事件动画?
- angular - Ng2SearchPipeModule 给出错误过滤器未找到
- reactjs - 折线图中的图例- google-charts-react