[转] 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 ...
随机推荐
- 使用Style自定义ListView快速滑动图标
一.显示ListView快速滑动块图标 设想这样一个场景,当ListView的内容有大于100页的情况下,如果想滑动到第80页,用手指滑动到指定位置,无疑是一件很费时的事情,如果想快速滑动到指定的位置 ...
- C#转义字符总结
转义字符 \·一种特殊的字符常量:·以反斜线"\"开头,后跟一个或几个字符.·具有特定的含义,不同于字符原有的意义,故称“转义”字符.·主要用来表示那些用一般字符不便于表示的控制代 ...
- 2015 年 Ruby 大盘点
2015 年 Ruby 圈发生了很多有趣的事,让我们跟随 Glenn Goodrich 来回顾一下 15 年 Ruby 的年度标志性事件. 2015 将要结束,这一年对于 Ruby 来说非常重要.如果 ...
- Ikki's Story IV - Panda's Trick
poj3207:http://poj.org/problem?id=3207 题意::平面上有一个圆,圆的边上按顺时针放着0..n-1共n个点.现在要连m条边,比如a,b,那么a到b可以从圆的内部连接 ...
- 树莓派学习路程No.1 树莓派系统安装与登录 更换软件源 配置wifi
在官网下载raspbian系统镜像,用Win32DiskImager写入TF卡 Image File 选择系统镜像,Device 选择TF卡盘符,Write即可.这样系统就写好了.把内存卡插进树莓派里 ...
- 【HDOJ】3308 LCIS
线段树,题目感觉比较难,看别人思路做的.还得继续练这个专题. #include <iostream> #include <cstdio> #include <cstrin ...
- HDU-2522 A simple problem
http://acm.hdu.edu.cn/showproblem.php?pid=2522 学习://除数的运算的应用和算法.除法的本质,如果余数出现重复就表示有循环节 A simple probl ...
- HDU-1969 Pie
http://acm.hdu.edu.cn/showproblem.php?pid=1969 Pie Time Limit: 5000/1000 MS (Java/Others) Memory ...
- Win32中文件的操作
1 文件的创建或打开 HANDLE CreateFile( LPCTSTR lpFileName, //文件路径和名称 DWORD dwDesiredAccess, //访问方式,最常用的值 ...
- Aix项目_shell_rsh_01
rsh(remote shell) 功能说明:远端登入Shell. 语 法:rsh [-dn][-l <用户名称>][主机名称或IP地址][执行指令] 补充说明:rsh提供用户环境,也就是 ...