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

86
Views
setState works when i empty obj manually instead of passing in the obj

I am trying to reuse an object in different components so my initial obj. is empty but when i export it into my component and setState to obj., it doesn't clear the state. but when I console.log the obj., it comes back as expected. any idea why this is happening?

this.state = {
  name: '',
  lastName: '',
  age: 0,
  kids: 0
}

const myEmptyObj = {
  name: '',
  lastName: '',
  age: 0
}

// lets pretend this function has name, lastName, age, and kids with values
// this function should clear the state but update the kids to value 3. so everything    
// empty but the kids field

myFunctionClearState() {
  myEmptyObj.kids = 3;
  setState(myEmptyObj);
}
about 4 years ago · Santiago Gelvez
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!