We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Redux 是 JavaScript 状态容器,提供可预测化的状态管理。Redux 除了和 React 一起用外,还支持其它界面库。 它体小精悍(只有2kB,包括依赖)。
https://github.com/xuya227939/blog/tree/master/examples/react-redux/my-app
$ sudo npm install -g create-react-app $ create-react-app my-app $ cd my-app $ npm install --save redux
$ sudo npm install -g create-react-app
$ create-react-app my-app
$ cd my-app
$ npm install --save redux
1.修改App.js,引用官方代码。
import React from 'react'; import { createStore } from 'redux'; function counter(state = 0, action) { switch (action.type) { case 'INCREMENT': return state + 1 case 'DECREMENT': return state - 1 default: return state } } let store = createStore(counter) store.subscribe(() => console.log(store.getState()) ) store.dispatch({ type: 'INCREMENT' }) store.dispatch({ type: 'INCREMENT' }) store.dispatch({ type: 'DECREMENT' }) const BasicExample = () => ( <div>123</div> ) export default BasicExample
2.npm start 调出开发者工具,看console.log输出。
这里以计数器为例子 https://github.com/xuya227939/blog/tree/master/examples/saga/my-app
$ sudo npm install -g create-react-app $ create-react-app my-app $ cd my-app $ npm install --save redux $ npm install --save redux-saga
$ npm install --save redux-saga
export function* addFun() { yield put({ type: "ADD" }); } function* homeSaga() { yield takeEvery("ADD_SAGA", addFun); }
function* Generato函数 homeSaga函数 监听action addFun函数 逻辑处理
function*
homeSaga函数
addFun函数
yield put({ type: "ADD" });
类似action的dispatch,发送数据到reducer
1.如果报类似这样的错,react-scripts command not found 那么就 $ rm -rf node_modules 模块,重新安装下 $ npm i,再重新npm start
The text was updated successfully, but these errors were encountered:
No branches or pull requests
Redux 介绍
Redux 是 JavaScript 状态容器,提供可预测化的状态管理。Redux 除了和 React 一起用外,还支持其它界面库。 它体小精悍(只有2kB,包括依赖)。
方法
Redux 例子
https://github.com/xuya227939/blog/tree/master/examples/react-redux/my-app
Redux 安装
$ sudo npm install -g create-react-app
$ create-react-app my-app
$ cd my-app
$ npm install --save redux
使用
1.修改App.js,引用官方代码。
2.npm start 调出开发者工具,看console.log输出。
Saga 介绍
方法
Saga 例子
这里以计数器为例子
https://github.com/xuya227939/blog/tree/master/examples/saga/my-app
Saga 安装
$ sudo npm install -g create-react-app
$ create-react-app my-app
$ cd my-app
$ npm install --save redux
$ npm install --save redux-saga
使用
function*
Generato函数homeSaga函数
监听actionaddFun函数
逻辑处理类似action的dispatch,发送数据到reducer
问题处理
1.如果报类似这样的错,react-scripts command not found 那么就 $ rm -rf node_modules 模块,重新安装下 $ npm i,再重新npm start
欢迎在此issue下进行交流、学习
结语
The text was updated successfully, but these errors were encountered: