Ashley Ferns
Ashley Ferns

Reputation: 93

I am getting undefined when i console log the response

export const getUsers = async() => {
    try {
        await axios.get(`${URL}/all`)
    } catch (error) {
        console.log("Error while calling getUsers API", error);
    }
}  

const getAllUsers = async () => {
    let response = await getUsers();
     console.log(response);
  }

When i console.log the data i get undefinded values but i can see the data in the network.

Help me solve this problem.

Upvotes: 0

Views: 31

Answers (1)

Muhammad Yousuf
Muhammad Yousuf

Reputation: 66

You are not returning the result, Use this.

export const getUsers = async() => {
  try {
    const response = await axios.get(`${URL}/all`)
    return response.data
  } catch (error) {
    console.log("Error while calling getUsers API", error);
  }
}

const getAllUsers = async () => {
  let response = await getUsers();
  console.log(response);
}

Upvotes: 2

Related Questions