使用 react 的状态管理方法 [英] State management approach using react

查看:51
本文介绍了使用 react 的状态管理方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经使用 react 一段时间了,有时我发现为简单的任务编写 action 和 reducer 很麻烦.我在这种情况下使用的方法如下

I have been using react for a while and at time I find it to be cumbersome to write action and reducers for simple tasks. The approach i use in such cases is as follows

我发现这种方法在实施时有效且不那么麻烦.这种方法的任何想法和缺点.

I find this approach to be effective and less cumbersome in implementing. Any thoughts and drawbacks of this approach.

推荐答案

React 没有定义你应该如何构建你的应用程序,也没有像其他一些框架(例如主干)那样建议默认"架构.此外,redux 不是 react 的必要部分.它用于防止状态分布在多个组件之间 - 但本地状态不是反模式,您确实可以/应该拥有一些.有关详细信息,请参阅 Redux 合著者的这篇文章.

React doesn't define how you should build your app and doesn't suggest a "default" architecture like some other frameworks (e. g. backbone) do. Also, redux is not a necessary part of react. It is used to prevent state from distributing across multiple components - but local state is not an antipattern and you indeed could/should have some. See this article from a redux co-author for details.

关于您在图片中提供的架构,嗯,这看起来像经典的 MVC.

Regarding the architecture you you provided on the pic, well, this looks like classic MVC.

  • 数据提供者组件"= 模型
  • 智能组件"= 控制器
  • 哑组件"= 视图

同样,react 并没有定义什么是错的,什么是对的.你的想法看起来不错.如果实施得当,就可以很清楚地理解.

Again, react doesn't define what is wrong and what is right. Your idea looks fine. With proper implementation it could be very clear to comprehend.

这篇关于使用 react 的状态管理方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆