React Native Api not responding at first time but responding on its second render

Viewed 30

when I hit api first time it giving me response status 200 but not showing any data in its response but if I hit it twice its doing its job perfectly. I am manging API Calls through redux.

1 Answers

As I already phase the same issue you need to return your response from the action Axios response and after that you will get the API response and return that response.

export const verifyCode = (data) => async dispatch => {
  try {
      const instance = axios.create();
      const response = await instance.post(API_PATHS.VERIFY_CODE, data);
      dispatch({ type: VERIFY_CODE, payload: response.data });
      return response.data;
  } catch (e) {
      dispatch({ type: VERIFY_CODE, payload: e });
      return Promise.reject(e);
  }
};
Related