javascriptreactjsreact-nativepostmanapisauce

Why am I unable to get response from my api using #apisauce?


Response is always returning undefined. I'm calling simple log in service using #apisauce in my react native app. Here's my implementation.

This is the handleSubmit method.

import loginApi from '../api/loginApi';

const handleSubmit = async ({email, password}) => {
    const result = await loginApi.login(email, password);
    console.log(result);
    console.log(result.data);
  };

Here is the Api call

import {create} from 'apisauce';

const apiClient = create({
  method: 'POST',
  baseURL: 'https://...',
  timeout: 10000,
});

export default apiClient;

And here's the api layer for login.

import apiClient from './client';

const loginApi = (email, password) => {
  apiClient.post('/login', {email, password});
};

export default {loginApi };

result always remains undefined. No error, no exceptions, nothing is coming in the result. I've checked the URLs, prams etc on #postman a number of times and everything is alright.


Solution

  • Result remains undefined because you're not returning anything from your loginApi.login() function.