Redux

74 阅读1分钟

store 下有index.js

1.index.js import {createStore} from 'redux' const store = createStore(fn)

redux提供creatStore这个函数,用来生成Store,createStore函数接受另一个函数作为参数,返回新生成的Store对象

const state= store.getStore()获取store的数据

2.action

action是一个对象,其中type属性是必须的,标识action名称

改变state的唯一办法,就是使用action,他会运送数据到Store

3.actionCreator

view要发送多少种消息,就会有多少种Action,如果都手写,会很麻烦,可以定义一个函数用来生成action,这个函数就叫Action Creator

redux-actions可以是actionCreator,也可以用来生成reducer,他的作用是用来简化action、reduceer,是react-redux的一个插件 使用命令行下载:npm install --save redux-actions

yarn add redux-actions