Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/26.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
Reactjs Redux Thunk:操作必须是普通对象_Reactjs_React Redux_Redux Thunk - Fatal编程技术网

Reactjs Redux Thunk:操作必须是普通对象

Reactjs Redux Thunk:操作必须是普通对象,reactjs,react-redux,redux-thunk,Reactjs,React Redux,Redux Thunk,我已经浏览了这里大部分关于这类问题的帖子,但我仍然没有运气。这就是我的操作,与redux thunk npm自述文件中的示例相同: const INCREMENT_COUNTER = 'INCREMENT_COUNTER'; function increment() { return { type: INCREMENT_COUNTER }; } function incrementAsync() { return dispatch => { setTimeo

我已经浏览了这里大部分关于这类问题的帖子,但我仍然没有运气。这就是我的操作,与redux thunk npm自述文件中的示例相同:

const INCREMENT_COUNTER = 'INCREMENT_COUNTER';

function increment() {
  return {
    type: INCREMENT_COUNTER
  };
}

function incrementAsync() {
  return dispatch => {
    setTimeout(() => {
      // Yay! Can invoke sync or async actions with `dispatch`
      dispatch(increment());
    }, 1000);
  };
}
存储设置如下,并传递给提供商:

export default createStore(
  rootReducer,
  applyMiddleware(thunk)
);

<Provider store={store}>
incrementAsync从连接的组件中调度,如下所示:

this.props.dispatch(incrementAsync);
我仍然得到未捕获的错误:操作必须是普通对象。使用自定义中间件进行异步操作。

NPM版本:

"react": "^16.3.2", 
"react-dom": "^16.3.2", 
"react-redux": "^5.0.7",
"react-router-dom": "^4.2.2", 
"redux": "^4.0.0", 
"redux-thunk": "^2.2.0"

是否有任何设置不正确的地方?

应该是
this.props.dispatch(incrementAsync())

而不是
this.props.dispatch(incrementAsync)

this.props.dispatch(incrementAsync)
取代

this.props.incrementAsync();
并在连接中绑定incrementAsync函数,如

connnect(null, { incrementAsync  }) (Component)

非常感谢。在这件事上把我的头发扯了好几个小时!
connnect(null, { incrementAsync  }) (Component)