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

191
Views
When to use react useState?

I have a very simple react code that doesn't work.

The value of the rotation from the console.log inside setTimeout is always { speed: 0, spinning: false } which was its initial value.

When do you actually use useState? What hook should I use for this simple code to work?

import React, { useEffect, useState } from 'react';
import './style.css';

export default function App() {
  const [rotation, setRotation] = useState({ speed: 0, spinning: false });

  const handleRotation = () => {
    if (!rotation.spinning) {
      setRotation({ speed: 0.02, spinning: true });
      setTimeout(() => {
        console.log(rotation);
        setRotation({ speed: 0, spinning: false });
      }, 3000);
    }
  };

  return (
    <div>
      <button onClick={handleRotation}>Spin</button>
    </div>
  );
}

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!