Search code examples
promisereduxredux-middleware

redux-auto: async actions are not firing


Hi all I have starting using this lib redux-auto and I want to talk to the my sever.

Here is my code - store/user/get.js

export default function (user, payload, stage, result) {

  switch(stage){
    case 'FULFILLED':
        return result;
      break;
    case 'REJECTED':
      console.error(user, payload, stage, result)
      break;
    case 'PENDING':
      console.log("should be loading")
    default :
      break;
  }
  return user;
}

export function action (payload){
  fetch('http://localhost:3000/api/users/'+payload.id).then( data => data.json() );
  return payload;
}

Here is the documentation. I cant see what is worry :(


Solution

  • You are not returning the promise from the fetch

    Change your action function to

    export function action (payload){
      return fetch('http://localhost:3000/api/users/'+payload.id).then( data => data.json() );
    }
    

    If you don't return a promise, redux-auto will treat it like a normal reducer.