Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

99
Views
Problem while setting data from API using useState - React

This is my res.data.enquiry - object I'm getting from api call

{
        active: true
         createdAt: "2021-09-03T05:58:32.584Z"
        ID: {category: Array(1),
          Images: Array(5),
          _id:'6131b96650a4b8127f7c59c8', 
           loginMethod: 0,
           phone: '65565656', …}
          messages: (4) [{…}, {…}, {…}, {…}]
             __v: 3
            _id: "COOK000000000036"
}

My UseState where I initialized the SingleEnq as an empty object to set it with res.data.enquiry during the fetch from api. (also tried null)

const [singleEnq, setSingleEnq] = useState({});

My fetch function

 function getOneticket(userID) {
        axios
          .get(`admin/enquiry/get/one?enquiryID=${userID}`)
          .then((res) => {
            setSingleEnq(res.data.enquiry)
          })
          .catch((err) => {
            console.log(err, "error message for get one ");
          });
      }

My useState remains empty. Dont know the reason. It's not setting up the data from the api.

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!