dvajs / dva

🌱 React and redux based, lightweight and elm-style framework. (Inspired by elm and choo)
https://dvajs.com/
MIT License
16.24k stars 3.17k forks source link

dva 的connect和React.memo函数无法连接,代码如下:cont App=()=>{ return <div></div>} export default connect(null,React.memo(App)),这样写页面直接报错 #2478

Closed wu-chunyi closed 2 years ago

wu-chunyi commented 2 years ago

What happens?

最小可复现仓库

请使用 yarn create umi 创建,选择 app,然后选上 dva,并上传到你的 GitHub 仓库

复现步骤,错误日志以及相关配置

相关环境信息

bybian commented 2 years ago

在项目上也遇到同样的问题 建议使用class组件替代React.memo函数

stale[bot] commented 2 years ago

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 1 year ago
 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)