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

106
Views
Change State - React

I define a state like this,

const [title, changeTitle] = useState('');

So, the value of the variable Title is an empty string.

Then, I receive a JSON, form :{active: '1', name: 'New Form', …}

I need to change the state title to New Form. changeTitle(form.name);

But then, the variable Title is undefined.

What am I doing wrong?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Make sure that when you call changeTitle the variable form.name is not undefined. If you are using react hooks and the variable form is a state or prop you can use a useEffect and change the state of title only when the variable form.name is defined

useEffect(() => {
 if(form.name){
  changeTitle(form.name);
 }
},[form.name]);
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!