简体   繁体   English

Redux-thunk 应用中间件

[英]Redux-thunk applyMiddleware

Just wondering why in this setup he put thunk in array and spread the middleware argument what is the difference between by just passing applyMiddleware (thunk).只是想知道为什么在这个设置中他将 thunk 放在数组中并通过传递 applyMiddleware (thunk) 来传播中间件参数有什么区别。

import { createStore, applyMiddleware } from "redux";
import { composeWithDevTools } from "redux-devtools-extension";
import thunk from "redux-thunk";
import rootReducer from "./reducers";

const initialState = {};

const middleware = [thunk];

const store = createStore(
  rootReducer,
  initialState,
  composeWithDevTools(applyMiddleware(...middleware))
);

export default store;

There is none.空无一人。 It is just preference, if you check the applyMiddleware signature it can take up to 5 middleware directly or if you want more than that you need this syntax.这只是偏好,如果您检查 applyMiddleware 签名,它最多可以直接占用 5 个中间件,或者如果您想要更多,则需要此语法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM