简体   繁体   English

Error get'Uncaught Error:操作必须是纯对象。 使用自定义中间件执行异步操作。” 由redux-thunk

[英]Error get 'Uncaught Error: Actions must be plain objects. Use custom middleware for async actions.' by redux-thunk

I try to write bellow code. 我尝试编写下面的代码。 but redux-thunk doesn't work. 但是redux-thunk不起作用。 Do you know how to resolve it? 你知道如何解决吗? When I exec this code, it can get this error. 当我执行此代码时,它会收到此错误。 createStore.js:113 Uncaught Error: Actions must be plain objects. Use custom middleware for async actions. But I already installed redux-thunk. 但是我已经安装了redux-thunk。 why does this error happen? 为什么会发生此错误?

index.js index.js

import { createDevTools } from 'redux-devtools';
import LogMonitor from 'redux-devtools-log-monitor';
import DockMonitor from 'redux-devtools-dock-monitor';
import React from 'react';
import ReactDOM from 'react-dom';
import { createStore, combineReducers, applyMiddleware, compose } from 'redux';
import { Provider } from 'react-redux';
import { Router, Route, IndexRoute, browserHistory } from 'react-router';
import { syncHistoryWithStore, routerReducer } from 'react-router-redux';
import thunk from 'redux-thunk';
import * as storage from './persistence/storage';
import randomToken from './utlis/random';
import * as reducers from './reducers';
import {
  App,
  Home
} from './components';

const reducer = combineReducers({
  ...reducers,
  routing: routerReducer
});

if (!storage.get('token')) {
  storage.put('token', randomToken());
}

const initialState = {
  application: {
    token: storage.get('token')
  }
};

const DevTools = createDevTools(
  <DockMonitor toggleVisibilityKey="ctrl-h" changePositionKey="ctrl-q">
    <LogMonitor theme="tomorrow" preserveScrollTop={false} />
  </DockMonitor>
);

const store = createStore(
  reducer,
  initialState,
  compose(
    applyMiddleware(
      thunk
    ),
    DevTools.instrument()
  )
);
const history = syncHistoryWithStore(browserHistory, store);

ReactDOM.render(
  <Provider store={store}>
    <div>
      <Router history={history}>
        <Route path="/" component={App}>
          <IndexRoute component={Home}/>
        </Route>
      </Router>
    </div>
  </Provider>,
  document.getElementById('app')
);

Map.js Map.js

import React from 'react';
import { connect } from 'react-redux';
import * as actions  from '../actions/cityForcast';

export class Home extends React.Component {
  constructor (props, context) {
    super(props, context);
  }

  componentWillMount () {
    this.props.dispatch(actions.search(this.props.token));
  }

  render() {
    return (
      <div>
        <button onClick={() => actions.search()}>Search</button>
      </div>
    );
  }
}

export default connect(({ application, cityForecast }) => ({ application, cityForecast }))(Home);enter code here

cityForcast.js cityForcast.js

export function search(token) {
  return dispatch => {
    console.log(token);
  };
}

I could resolve that for myself. 我可以自己解决这个问题。 I needed to install redux-thunk as devDependencies as well. 我还需要安装redux-thunk作为devDependencies。

暂无
暂无

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

相关问题 Redux-Thunk 错误:操作必须是普通对象。 使用自定义中间件进行异步操作 - Redux-Thunk Error: Actions must be plain objects. Use custom middleware for async actions 错误:动作必须是普通对象。 使用自定义中间件进行异步操作。 React-redux错误 - Error: Actions must be plain objects. Use custom middleware for async actions. React-redux error 动作必须是普通对象。 使用自定义中间件进行异步操作。 React,Redux,Thunk - Actions must be plain objects. Use custom middleware for async actions. React, Redux, Thunk 错误:操作必须是普通对象。 使用自定义中间件进行异步操作。 Redux 工具包 - Error: Actions must be plain objects. Use custom middleware for async actions. Redux toolkit 如何修复:错误:操作必须是普通对象。 使用自定义中间件进行异步操作。? - How to fix: Error: Actions must be plain objects. Use custom middleware for async actions.? Redux Mock Store给出&#39;动作必须是普通对象。 使用自定义中间件进行异步操作。 - Redux Mock Store giving 'Actions must be plain objects. Use custom middleware for async actions.' 异步操作 Redux 未处理拒绝(错误):操作必须是普通对象。 使用自定义中间件进行异步操作 - Async Action Redux Unhandled Rejection (Error): Actions must be plain objects. Use custom middleware for async actions React - Native &#39; Redux Uncaught Error: Actions 必须是普通对象。 按下按钮时使用自定义中间件进行异步操作 - React - Native ' Redux Uncaught Error: Actions must be plain objects. Use custom middleware for async actions' on button press 错误:操作必须是普通对象。 使用自定义中间件进行异步操作。 我究竟做错了什么? - Error: Actions must be plain objects. Use custom middleware for async actions. What am I doing wrong? componentwillmount() 未捕获错误:操作必须是普通对象。 使用自定义中间件进行异步操作 - componentwillmount() Uncaught Error: Actions must be plain objects. Use custom middleware for async actions
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM