美文网首页
redux中使用中间件的两种方法(笔记)

redux中使用中间件的两种方法(笔记)

作者: duziten | 来源:发表于2017-11-29 17:36 被阅读0次

两种方法都需要使用redux提供的applyMiddleware函数

第一种方法:使用applyMiddleware包装 createStore产生一个新的创建store 的函数。(实际上是一个Store Enhancer)

例:

import {createStore , applyMiddleware} from ’ redux ’ J
import thunkMiddleware from ’ redux- thunk ’
const configureStore = applyMiddleware (thunkMiddleware) (createStore);
const store= configureStore (reducer , initialState) ;
第二种方法:同样把applyMiddleware结果当做Store Enhancer,和其他Enhancer混合之后作为 createStore的参数传入。
import {createStore , applyMiddleware , compose} from ' redux ’;
import thunkMiddleware from ’ redux- thunk ’
const win = window;
const storeEnhancers =compose (
applyMiddleware (. . .middlewares ),
(win && win .devToolsExtension) ? win. devToolsExtension () : f => f
const store= createStore (reducer , storeEnhancers );

相关文章

  • 中间件redux-thunk使用过程

    使用redux-thunk创建加强版store的过程图: redux提供了使用中间件的方法:applyMiddle...

  • Day17. Redux深入

    如何使用redux-thunk 中间件的使用, redux-thunk redux-devtools redux开...

  • redux搭配中间件实现状态管理

    在Vue中可以使用vuex,在react可以使用dva(基于redux-saga实现)或者使用redux搭配中间件...

  • redux中使用中间件的两种方法(笔记)

    两种方法都需要使用redux提供的applyMiddleware函数 例:

  • 2-Redux中间件

    Redux 中间件 [toc] Redux 中间件的作用 Reudx 中的中间件是通过对 dispatch 进行的...

  • redux-thunk入门

    今天来介绍在使用redux中必不可少用要用到的中间件redux-thunk。如果还没有看过我之前关于redux介绍...

  • 09-采用React Saga的心路历程

    我们在之前的实现中,对于异步 Action 的调用使用了 redux-saga 中间件。thunk 中间件通过增强...

  • redux

    使用步骤 redux只处理同步 redux处理异步请求中间件· 在引入redux的时候引入applyMiddlew...

  • 01从源码角度看compose

    compose compose是redux使用的一个方法. 该方法可以将多个中间件方法糅合成一个方法. 试想以下问...

  • redux-saga 简单入门使用

    redux架构中,如果action里有诸如网络请求、磁盘读写等异步操作,会提示使用中间件解决。redux-saga...

网友评论

      本文标题:redux中使用中间件的两种方法(笔记)

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