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

142
Views
No se puede realizar una actualización de estado de React en un componente desmontado para setInterval

Recibo una advertencia "No se puede realizar una actualización de estado de React en un componente desmontado" cuando estoy ejecutando este código

 function timer() { const [dateState, setDateState] = useState(new Date()); useEffect(() => { setInterval(() => setDateState(new Date()), 1000); }, []); return( <div className="container"> <p className="text-end text-danger">{dateState.toLocaleDateString('fr-BE' , { day : 'numeric', month : 'short', year: 'numeric' })}</p> <div className="text-center"> <h3 className="text-info"> {dateState.toLocaleString('fr-BE', { hour: 'numeric', minute: 'numeric', second : 'numeric', hour24: true, })} </h3> </div> </div> ) } export default timer;

traté de hacer

 const [dateState, setDateState] = useState(new Date()); useEffect(() => { let mount = true; if(mount){ setInterval(() => setDateState(new Date()), 1000); } return () => { isMounted = false }; }, []);

Pero sigo sin funcionar, estoy un poco atascado...

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

0

Debe limpiar el temporizador setInterval en el desmontaje del componente, como:

 useEffect(() => { const interval = setInterval(() => setDateState(new Date()), 1000); return () => { clearInterval(interval); } }, []);
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!