美文网首页
Redux常用方法

Redux常用方法

作者: 07120665a058 | 来源:发表于2017-05-22 21:32 被阅读67次

    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);
    

    相关文章

      网友评论

          本文标题:Redux常用方法

          本文链接:https://www.haomeiwen.com/subject/trhixxtx.html