dva 的connect和React.memo函数无法连接,代码如下:cont App=()=>{ return <div></div>} export default connect(null,React.memo(App)),这样写页面直接报错
wu-chunyi opened this issue · 3 comments
wu-chunyi commented
What happens?
最小可复现仓库
请使用
yarn create umi
创建,选择app
,然后选上dva
,并上传到你的 GitHub 仓库
复现步骤,错误日志以及相关配置
相关环境信息
- Umi 版本:
- Node 版本:
- 操作系统:
bybian commented
在项目上也遇到同样的问题 建议使用class组件替代React.memo函数
stale commented
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
SunXinFei commented
export default memo(connect(({ baseInfoDva }) => ({
baseInfoDva
}), null)(BaseTitle), (prevProps, nextProps) => {
// 这里由于dva的bug,导致memo无法拿到dva的数据
})
真正的解法是再包一层组件,最底层的组件用memo包裹,外部是connect
const BaseTitle233 = memo((props)=>{
},(prevProps, nextProps) => {
// 这里可以拿到dvg数据
}))
function BaseTitle(props){
return <BaseTitle233 {...props}></BaseTitle233>
}
export default connect(({ baseInfoDva }) => ({
baseInfoDva
}), null)(BaseTitle)