其他分享
首页 > 其他分享> > Redux中间件

Redux中间件

作者:互联网

Redux中间件

1、applyMiddleware
import {createStore,applyMiddleware} from 'redux';
import reducers from './reducers';
import Logger from 'redux-logger';

export default createStore(reducers, applyMiddleware(Logger))
2、redux-thunk
dispatch((dispatch, getState)=>{
    // getState可以获取全局的state
    dispatch({
        type:"START"
    })
    fetch('/data.json')
    .then(res=>res.json())
    .then(success=>{
        if(success){
            dispatch({
                type:"FETCH_LIST",
                payLoad:success.arr
            })
        }else{
            dispatch({
                type:"FETCH_TAIL"
            })
        }
    })
})
3、redux-saga
4、redux-thunk

标签:redux,applyMiddleware,中间件,dispatch,action,import,Redux,reducers
来源: https://blog.csdn.net/weixin_45290863/article/details/97611508