Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Redux 为什么thunk的参数被包装在一个对象中?_Redux_Thunk - Fatal编程技术网

Redux 为什么thunk的参数被包装在一个对象中?

Redux 为什么thunk的参数被包装在一个对象中?,redux,thunk,Redux,Thunk,我试图理解redux中的thunks: const thunk = ({ dispatch, getState }) => next => action => { if (typeof action === 'function') { return action(dispatch); } return next(action); }; 我很难理解为什么参数被作为对象传递(或者是对象解构?)。为什么不将它们作为dispatch,getState传递?Redu

我试图理解redux中的thunks:

const thunk = ({ dispatch, getState }) => next => action => {
  if (typeof action === 'function') {
    return action(dispatch);
  }
  return next(action);
};

我很难理解为什么参数被作为对象传递(或者是对象解构?)。为什么不将它们作为
dispatch,getState
传递?

Redux中间件被提供一个Redux存储API的微型版本作为最外层函数的参数。完整存储API是
{dispatch,subscribe,getState,replaceReducer}
。中间件只能访问
{dispatch,getState}

至于为什么它是一个对象而不是单独的参数

const middlewareAPI={
getState:store.getState,
调度:(…args)=>调度(…args)
}
const chain=middleware.map(中间件=>middleware(middlewareAPI))
dispatch=组合(…链)(store.dispatch)