dvdzkwsk / react-redux-starter-kit

Get started with React, Redux, and React-Router.
MIT License
10.29k stars 2.2k forks source link

The payload is returning undefined when accessing the API. #1280

Closed mfgabriel92 closed 7 years ago

mfgabriel92 commented 7 years ago

Greetings,

I'm using react-redux-starter-kit's latest release on the front-end, and Django 1.11.2 on the back-end.

In the release version 2.0.0, the configurations I've learned that are necessary to communicate with the back-end worked, but now with the newest release I'm experiencing an undefined payload when accessing the endpoint responsible for simply returning data.

These are the following I've done to make it communicate with the API. Starting with server/main.js, I've added:

const proxy = require('express-http-proxy')

app.use('/api', proxy('http://127.0.0.1:8000'))

Then, inside createStore.js:

import { apiMiddleware } from 'redux-api-middleware'

const createStore = (initialState = {}) => {
  const middleware = [thunk, apiMiddleware, routerMiddleware(history)]
  ...
  const store = createReduxStore(
      ...
      applyMiddleware(...middleware),
      ...

Then, I created Redux actions, located in store/modules/, for example:

import { CALL_API } from 'redux-api-middleware'
.....
export function categoryList() {
  return {
    [CALL_API]: {
      endpoint: '/api/categories',
      method: 'GET',
      types: [CATEGORY_LIST, CATEGORY_LIST_SUCCESS, CATEGORY_LIST_FAILURE],
    },
  }
}
....
const ACTION_HANDLERS = {
  [CATEGORY_LIST]: state => ({
  ..
  }),
  [CATEGORY_LIST_SUCCESS]: (state, action) => ({
  ...
  }),
  [CATEGORY_LIST_FAILURE]: (state, action) => ({
  ...
  })
}
...
const initialState = {
  ...
}

export default function userReducer(state = initialState, action) {
  ...
}

I'd then import these methods within the containers/ within routes/ and access it from the component, which then returns payload: undefined if I console.log the action parameter.

I'm posting here wondering if there'd be something else to be done on this new release.