[转] What is the point of redux when using react?
As I am sure you have heard a bunch of times, by now, React is the V in MVC. I think you can think of Redux as the M. Really, React + Redux kind of also act as the C.
So, you could just manage your state directly within your React components, and in a really simple app you probably should. However, if your app is going to have a lot of components with various states and likely some sort of user input/data retrieval, that is quickly going to become a pain to manage. This is where Redux can help.
If nothing else, read this section from the docs: http://redux.js.org/docs/introduction/Motivation.html It does a great job of explaining the why.
If Redux is not your thing, you can also check out Mobx. http://mobxjs.github.io/mobx/ Some find this a little easier to grok.
Hope this helps.
Redux and React solve separate problems, but those problems are often found "together" when building apps.
What React does is manage the "view" -- what elements are displayed on the page, what relationship they have to other elements, and what relationships that they hold to each other. In order to do that, React breaks up web pages into little modules called "Components." Each component can have a "component state," which is basically a big object that stores all your data. What's important to know about this object is that whenever you make a change to it, React is smart enough to know that it needs to re-render all the items that were using the information in the component state. That way, you can create apps that respond to user interaction without a whole lot of code.
Flux (of which Redux is an implementation) solves a different problem. Flux doesn't manage views at all, but like a Redux component, it manages the state of your application as a whole. It is designed to be a replacement for the traditional "Model-view-controller" framework.
Generally anything that requires you to use a database, query an API, etc, should probably be handled in a flavor of Flux. If you're just changing the view, you can get buy with just React.
As it turns out, it is possible to build out an application with a React front-end and not use Flux... we essentially built a model-view-controller application where React served as the view for our thesis project at MakerSquare... but Flux works with react because while they solve different problems, they solve those different problems in similar ways.
Redux is a particular type of Flux implementation that allows for a lot of really good features when it comes to debugging and logging, which is why people are raving about it. The learning curve is steep but plateaus -- once you get it, you start to realize why people tend to like it.
React shouldn't be responsible for data. It's View library. React components should hold self-related data (eg.: active, color, etc.)
Also, sometimes two or more components and perhaps something else might need same data - so you obviously cant store it in one component.
Redux, Flux and other *ux, solves all those problems.
Put simply, Redux acts as a store of state. A typical React app defines many different components. These components all require some state to be rendered correctly, e.g. the current user, what's being looked at, etc. Redux shares state globally across all the different components. Having centralized state reduces the complexity of managing the state transitions and makes access easier. Redux also implements the observer patterns, so consumers of state can be notified on state changes and rerendered.
state tree
single source of truth
[转] What is the point of redux when using react?的更多相关文章
- Redux:with React(一)
作者数次强调,redux和React没有关系(明明当初就是为了管理react的state才弄出来的吧),它可以和其他插件如 Angular, Ember, jQuery一起使用.好啦好啦知道啦.Red ...
- [Redux] Filtering Redux State with React Router Params
We will learn how adding React Router shifts the balance of responsibilities, and how the components ...
- [Redux] Navigating with React Router <Link>
We will learn how to change the address bar using a component from React Router. In Root.js: We need ...
- 实例讲解react+react-router+redux
前言 总括: 本文采用react+redux+react-router+less+es6+webpack,以实现一个简易备忘录(todolist)为例尽可能全面的讲述使用react全家桶实现一个完整应 ...
- react+redux官方实例TODO从最简单的入门(6)-- 完结
通过实现了增-->删-->改-->查,对react结合redux的机制差不多已经了解,那么把剩下的功能一起完成吧 全选 1.声明状态,这个是全选状态 2.action约定 3.red ...
- Redux教程2:链接React
通过前面的教程,我们有了简单的环境,并且可以运行Redux的程序,也对 如何编写Redux示例 有了初步的印象: 掌握了 使用Redux控制状态转移 ,继而驱动 React 组件发生改变,这才是学习R ...
- 使用Redux管理你的React应用
因为redux和react的版本更新的比较频繁,博客园这里用的redux版本是1.0.1,如果你关心最新版本的使用技巧,欢迎来我的Github查看(https://github.com/matthew ...
- Redux你的Angular 2应用--ngRx使用体验
Angular2和Rx的相关知识可以看我的Angular 2.0 从0到1系列第一节:Angular 2.0 从0到1 (一)第二节:Angular 2.0 从0到1 (二)第三节:Angular 2 ...
- Redux管理你的React应用
使用Redux管理你的React应用 因为redux和react的版本更新的比较频繁,博客园这里用的redux版本是1.0.1,如果你关心最新版本的使用技巧,欢迎来我的Github查看(https ...
随机推荐
- keil对51单片机变量和函数的编译处理
(1)初始值不是0的全局变量 在程序调到main()函数执行前,除了要进行内存清零.初始化堆栈外,还需要将全局变量的初始值加载到RAM的指定区域(编译过程中为全局变量分配的空间). (2)未初始化的局 ...
- MAC OX 配置JDK环境变量
大家在windows里面配置JDK环境变量很容易,但是如果要在mac里面配置JDK环境变量和windows里面有所不同,具体如下: 第一: mac OS里面自带jdk,不过是1.6的版本,现在很多人使 ...
- Netty启动分析
基于Netty-3.2.5 先看一段Netty的服务端代码: import java.net.InetSocketAddress; import java.util.concurrent.Execut ...
- 邮件协议POP3/IMAP/SMTP服务的区别
2016年09月09日 09時51分 wanglinqiang整理 通过网上查找的资料和自己的总结完成了下面的文章,看完之后相信大家对这三种协议会有更深入的理解.如有错误的地方望指正. POP3 PO ...
- python 文件及文件夹操作
python 文件.目录操作(新增.移动.删除等) python 文件夹与文件操作 mport string, os, sys dir = '/var' print '----------- no s ...
- swift中类似宏定义
建一个类 如,在Contans.swift中 import UIKit let kMAIN_SIZE = UIScreen.mainScreen().bounds 在其他地方直接用 比如在 MyTab ...
- html5--indexedDB
http://www.cnblogs.com/Johnny_Z/archive/2012/11/04/2753331.html http://database.51cto.com/art/201202 ...
- 用了OneAPM CT,宕机早知道!
Twitter 的公司网站和移动应用在 1 月 19 日早上出现宕机,导致全球部分地区用户无法正常访问.这次宕机影响了很多用户,英国和印度用户已经无法访问 Twitter .第三方监测机构 DownD ...
- Delphi能通过SSH登录Linux,连接MYSQL取数么?像Navicat一样
百度随时就能搜,你就懒得搜下.http://tieba.baidu.com/p/671327617 Ssh tunnel通常能实现3种功能1) 加密网络传输2) 绕过防火墙3) 让位于广域网的机器连接 ...
- 两种QMultiMap的遍历方法(最好使用只读遍历器)
留个爪,备查 QMultiMap<QString, QString>& remote_map = my_obj->m_MapVersion; // ccc 这里体现了引用的好 ...