0

I have a function that gets data from API I assign the response in const then just use the constant to assign a new variable to use it when setting state but when I log them it returns undefined! Does anyone have an explanation about it?

const getProfile = async ()=>{
const res = await Api.post(
      '/get/vendor/service',
      {
        vendor_id: vendor_id,
      },
      {
        headers: headers,
      },
    );
    const vendorData = res.data.vendor;
    const allServices = vendorData.services;
    const allEmployee = vendorData.employies;

    setVendor(vendorData);
    setServices(allServices);
    setEmployees(allEmployee);
    console.log('vendorData', vendorData); // all response
    console.log('allServices', allServices); // log undefined 
  };

Response sample

id: 3
latitude: "37.33"
longitude: "-122.12"
file: "public/files/3Eb6Bb846IyxOK89v7QSiolZBrRoUXOTE66dUyvR.pdf"
image: "public/vendor/41EpEXNukGujAzsqcKt2EqadQ56JZBLxcv1bb1nO.png"
created_at: "2020-08-25 17:39:57"
updated_at: "2020-08-25 17:40:36"
services: [{…}]
employies: []
Oliver D
  • 2,579
  • 6
  • 37
  • 80

0 Answers0