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

66
Views
React State Shows False When True Is Expected

Very simple goal. When a checkbox is clicked set the state of itemOne to true initially. Then it should toggle state if clicked again. When itemOneSelected is invoked itemOne is shown as false.

The question: Why is itemOne set to false instead of true when itemOneSelected is invoked?

      const [itemOne, setItemOne] = useState(false);
      const itemOneSelected = () => {
      setItemOne(!itemOne)
      console.log(itemOne)
      }

    
      <FormControlLabel control={<Checkbox onClick => { itemOneSelected() } } />} 
about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Remember useState is asynchronous so it will not update straight away. To get the console.log value to log your value you should add a useEffect.

    useEffect(() => {
        console.log(itemOne) 
    },[itemOne])
about 4 years ago · Santiago Trujillo 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!