Redux-Saga response is undefined

I'm having response is undefined on my request using redux-sagas and axios

export function* getCompanies({ payload }: any) {
  try {
    const { data: response } = yield call(api.get, '/companies-list', {
      params: {
        keyword: payload,
      },
    });
    console.error(response); // RETURNS NULL
    const { data } = response;
    yield put(handleFetchCompaniesAsync.success(data.companies));
  } catch ({ response }) {
    yield all([
      put(handleFetchCompaniesAsync.failure(response.data)),
      put(handleAsyncNotification(response.data)),
    ]);
  }
}

When trying to log the response it says null

Upvotes: 0

Views: 886

Answers (1)

Tomer
Tomer

Reputation: 1568

Your saga looks ok and should be working

I think you should check your api.get endpoint. if you are not returning your fetch call, that might be the reason for this undefined.

For example:

--V-- this is probably what your are missing
return fetch('http://localhost:3000')
        .then((res) => {
            // bla bla bla
            return res.json();
        })
        .catch((err) => {
            // bla bla bla
        });

Upvotes: 1

Related Questions