gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-03 13:43:45 25 4
gpt4 key购买 nike

我有一个问题:

将 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com