reactjs - 将 HOC 与 React Hooks 一起使用仍然有意义吗?

标签 reactjs react-hooks

我有一个问题:

将 HOC 与 React Hooks 一起使用仍然有意义吗?

如果是,在什么情况下使用它是个好主意?

谢谢。

最佳答案

根据official docs ,仅当 HOC 需要做的不仅仅是渲染单个子项时:

Do Hooks replace render props and higher-order components?

Often, render props and higher-order components render only a single child. We think Hooks are a simpler way to serve this use case. There is still a place for both patterns (for example, a virtual scroller component might have a renderItem prop, or a visual container component might have its own DOM structure). But in most cases, Hooks will be sufficient and can help reduce nesting in your tree.

据我解释,react-redux connect不过 useSelector and useDispatch 仍然是一个有效的 HOC可用,所以为什么要麻烦 ́\_(ツ)_/́

关于reactjs - 将 HOC 与 React Hooks 一起使用仍然有意义吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55656499/

相关文章:

javascript - 如何在 react 中验证多步表单

javascript - 映射 react Hook 后如何从api发送值

reactjs - 忽略某些 React useEffect 依赖项警告是否正确?

javascript - react : pass Component as prop and use it with additional props

reactjs - 使用 useEffect,如何跳过在初始渲染时应用效果?

javascript - 在 GraphQL 查询模板中使用 React Prop (字符串)

reactjs - 减少大型、基于 React 的单页应用程序的 Browserify 捆绑文件的大小

javascript - 使用 useRef 在 React Hooks 中恢复滚动位置不稳定

javascript - 类型错误 : Cannot destructure property 'jobArray' of 'react__WEBPACK_IMPORTED_MODULE_0__.state' as it is undefined

javascript - 如何从 Instagram 获取网站的动态数据