Reactjs 减速机不';在调度操作时无法捕获

Reactjs 减速机不';在调度操作时无法捕获,reactjs,api,redux,Reactjs,Api,Redux,我想在我的小react/redux应用程序中进行api调用。我仍在学习redux,所以显然我在这方面并不完美。 我的问题是:当我调用api时,reducer不能从操作中获取数据。 当我登录控制台操作负载时,它从服务器获取正确的数据。外翻看起来还可以,但reducer并没有意识到动作已经发生了。这是我的密码: actions/apicall.js import Api from '../api/Api'; import * as types from './actionsTypes'; expo

我想在我的小react/redux应用程序中进行api调用。我仍在学习redux,所以显然我在这方面并不完美。 我的问题是:当我调用api时,reducer不能从操作中获取数据。 当我登录控制台操作负载时,它从服务器获取正确的数据。外翻看起来还可以,但reducer并没有意识到动作已经发生了。这是我的密码:

actions/apicall.js

import Api from '../api/Api';
import * as types from './actionsTypes';

export function loadSuccess(payload){
console.log(payload)
return {type: types.DATA_LOADED, payload}
};

export function loadData() {
  return function(dispatch) {
    return Api.getAllBeers().then(payload => {
      loadSuccess(payload);
      console.log(payload);
   }).catch(error => {
     throw(error);
   });
  };
}
减速器/数据减速器

import initialState from './initialState';
import * as types from '../actions/actionsTypes';

export default function beerReducer(state = initialState, action) {
console.log(state);
console.log(action.payload);
  switch(action.type) {
    case types.DATA_LOADED:
      return action.payload
    case types.SELECTED_BEER:
      return action.payload
    default:
     return state;
 }
}
还原剂/指数

import { combineReducers} from 'redux';
import beerReducer from './data_reducer';

const allReducers = combineReducers({
    beerReducer,
});

export default (allReducers);
api/api

class Api {
  static getAllBeers() {
      const request = new Request(`https://api.punkapi.com/v2/beers`, {
  method: 'GET'
});
    return fetch(request).then(response => {
      return response.json();
    }).catch(error => {
      return error;
    });
  }
}
export default Api;
index.js

import React from 'react';
import ReactDOM from 'react-dom';
import './resources/css/main.css';
import App from './resources/App';
import {Provider} from 'react-redux';
import configureStore from './store/configureStore';
import {loadData} from './resources/actions/apicall';

const store = configureStore();

store.dispatch(loadData());

ReactDOM.render(
    <Provider store={store}>
    <App/>
</Provider>, document.getElementById('root'));
从“React”导入React;
从“react dom”导入react dom;
导入“/resources/css/main.css”;
从“./resources/App”导入应用程序;
从'react redux'导入{Provider};
从“/store/configureStore”导入configureStore;
从“./resources/actions/apicall”导入{loadData};
const store=configureStore();
store.dispatch(loadData());
ReactDOM.render(
,document.getElementById('root');
你知道怎么了吗?
提前感谢

您必须在
apicall.js中发送操作

调度(装载成功(有效载荷))

您必须在
apicall.js
中调度操作:
调度(装载成功(有效载荷))