connect()(memo(App)) 语法没错,dva一些版本不兼容
yarn update react-redux to the version that mentioned by @Maxime Chéramy at least
- 原因:conect包裹的组件,必须是 function
- memo(App) 返回的是 object 对象类型,所以报错
https://stackoverflow.com/questions/52998469/how-to-use-react-memo-with-react-redux-connect
// 报错
export default connect(
mapStateToProps,
mapDispatchToProps,
)(memo(User));
Uncaught Invariant Violation: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: undefined.
You likely forgot to export your component from the file it’s defined in, or you might have mixed up default and named imports.
For someone who want to know why react-redux throw this error.
For me, I used version 5.0.7, react-redux/src/components/connectAdvanced.js line: 92
invariant(
typeof WrappedComponent == 'function',
`You must pass a component to the function returned by ` +
`${methodName}. Instead received ${JSON.stringify(WrappedComponent)}`
);
// After upgrading this code is changed to :
invariant(
isValidElementType(WrappedComponent),
`You must pass a component to the function returned by ` +
`${methodName}. Instead received ${JSON.stringify(WrappedComponent)}`
);
原因:conect包裹的组件,必须是 function, WrappedComponent == ‘function’
dva 版本是2.4.1
“react-redux”: “5.0.7”, react-redux版本被写死了,react-redux 5.1修复了这个错误
https://github.com/dvajs/dva/issues/2421