action创建函数
const addTask = (text)=> {
return {
type: ADD_TODO,
text
}
}
module.exports={addTask};
combineReducers
- 合并多个
reducer
,返回一个对象
import {combineReducers} from 'redux';
function todos(state = [], action) {
...
return state;
}
export default combineReducers({
todos
});
createStore / applyMiddleware
-
createStore()
创建的redux store
只支持同步数据流 - 引入
applyMiddleware()
可以处理异步请求
import {createStore,applyMiddleware} from 'redux';
import reducer from './reducers';
import middle from './middleware';
const Middleware = applyMiddleware(middle);
let store = createStore(reducer, Middleware);