0

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 :(

aSmater.Me
  • 1,014
  • 7
  • 13

1 Answers1

1

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.

Brian
  • 1,026
  • 1
  • 15
  • 25