Search code examples
javascriptreactjsreact-nativeasynchronouses6-promise

React Native: Possible Unhandled Promise Rejection (id: 0): TypeError: undefined is not an object


I have a React Native application that I cloned and after registering into the app on my simulator, I get this yellow error at the bottom of the screen which says:

Possible Unhandled Promise Rejection (id: 0): TypeError: undefined is not an object (evaluating 'data.Items')

I believe it has to be referencing one or all of these action creators in this file:

export function fetchPrefences({Key}) {
  return dispatch => {
    const url = `${endpoints.v2.INDIVIDUALS}/${Key}/preferences`;
    requester.sendGet(url).then(data => {
      const payload = helpers.sortPreferences(data);
      dispatch({
        type: types.SET_USER_PREFERENCES,
        payload,
      });
    });
  };
}

export function fetchTopics() {
  return dispatch => {
    requester.sendGet(endpoints.TOPICS_OF_CONCERN).then(data => {
      dispatch({
        type: types.SET_USER_TOPICS,
        payload: data.Items,
      });
    });
  };
}

export function handleUpdateTopics({topics, involved}, updateBoth = false) {
  return dispatch => {
    return requester
      .sendPut(endpoints.TOPICS_OF_CONCERN, {
        Items: topics,
      })
      .then(data => {
        dispatch({
          type: types.SET_USER_TOPICS,
          payload: data.Items,
        });
        if (updateBoth) {
          dispatch(handleUpdatePreferences({involved}));
        }
      });
  };
}

I have written asynchronous action creators in the past, but I can't see what is wrong with these. Is it that data is undefined? If so, my question would be, how is this possible if in other areas of the application data is being used with no obvious errors?


Solution

  • Your data result is undefined ... it has nothing todo with your redux action One easy and straight forward way to check your api-endpoint is postman ...