本文介绍了挂钩会否推翻redux?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在搜索关于React的钩子的一段时间,一个问题在我脑海中持续存在.挂钩会否推翻redux?这是一个相当古老的讨论,因此先介绍一下上下文:

I've been searching for a while about React's hooks now, and one question became persistent in my head. Will hooks overthrown redux? This is a fairly old discussion so first a little bit of context :

  • State Management with React Hooks — No Redux or Context API
  • What do Hooks mean for popular APIs like Redux connect() and React Router?
  • redux-react-hook

很多人(包括React的团队)似乎认为redux和类似的东西只会适应新的API,从而使HOC的方法过时了,但是我的问题是:

使用自定义钩子,使用reducer ,以及深思熟虑的逻辑为什么我需要完全没有Redux吗?我的意思是,将您的操作分派给单个reducer不仅表现得更好吗?我找到了很多相关的材料,但是似乎没有一个明确的答案(也许是因为没有答案?),所以我想知道您对Redux的未来有何看法?

A lot of people (React's team included) seens to think that redux and similars will just going to adapt to the new API, turning the HOC's approach obsolete, but my question is:

With custom hooks, use reducer, and a well thought logic why do I need Redux at all? I mean, isn't just more performatic to dispatch your actions to a single reducer? I've found a lot of material about it, but none of those seems to have a definitive answer (maybe because there aren't one?), so I would like to know what do you think about Redux's future?

推荐答案

不,绝对不是.

我在我的 Reactathon 2019演讲国家Redux" .

总结:钩子大多数提供了完成已经可以做的相同事情的方式,例如本地组件状态和避免通过上下文进行钻探.如果这就是使用Redux的全部,那么您可能一开始就不需要Redux.但是,钩子有其局限性,选择Redux还有很多其他用例.

Summarizing: hooks mostly offer ways to do the same kinds of things you could already do, like local component state and avoiding prop-drilling via context. If that's all you were using Redux for, then you probably didn't need Redux in the first place. But, hooks have their limitations, and there's lots of additional use cases for choosing Redux.

此外,请注意,我们正在目前正在设计公共useRedux()类型钩住React-Redux的API .

Also, note that we are currently working on designing a public useRedux()-type hooks API for React-Redux.

这篇关于挂钩会否推翻redux?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-24 16:00