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

158
Views
Diferencia entre "useState(() => JSON.parse(localStorage.getItem("count")));" y useState(JSON.parse(localStorage.getItem("count")));

//almacenar el conteo en localStorage //obtener el valor de localStorage y establecer el valor inicial en el conteo

// Solución uno: JSON.parse se llamará a cada renderizado

 const [count, setCount] = useState(JSON.parse(localStorage.getItem("count"))); useEffect(() => { localStorage.setItem("count", JSON.stringify(count)); }, [count]);

// Solución 2: función de inicialización de useState

 const [count, setCount] = useState(() => JSON.parse(localStorage.getItem("count")) ); useEffect(() => { localStorage.setItem("count", JSON.stringify(count)); }, [count]);

Mi pregunta: ¿Cómo es que la solución 2 evitará que el código llame a JSON.parse cada renderizado?

Gracias

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!