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

207
Views
React state hook Object not updating, getting [Object object]

In my project I am having trouble setting a state variable with a javascript object, I can see in my console logs that the object is being instansiated correctly with the right values, but I cannot figure out why it is not properly setting the state hook.

Any help would be appreciate!!

const [accountInfo, setAccountInfo] = useState({})

const delay = ms => new Promise(res => setTimeout(res, ms));

const onLogin = async (account) => {

    await(delay(2000));

    console.log(account); // I am getting the proper output of the object here

    if(account.account_id != -1){

      setAccountInfo(account);

      await delay(4000); //Just for debugging
      console.log("acc " + accountInfo); // This outputs [Object object]
      setLoggedIn(true);
    }else{
      alert('Account does not exist');
    }
  }
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You are trying to concatenate string with object. Either convert object to string with JSON.stringify or use object.property.

console.log("Object" + JSON.stringify(object_to_print));

you are trying to console.log a state variable. React is not guaranteeing the state change immediately. you can access state change in useEffect hook

useEffect(() => { 
      console.log('state changed', your-state-variable) 
      // write your callback function here
 }, [your-state-variable]);
about 4 years ago · Juan Pablo Isaza Report
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!