Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

109
Vistas
checkbox not displaying check mark correctly

I have a react form that gets the status of a checkbox element from local storage with useEffect.

const [checkbox, setCheckbox] = useState(false);

useEffect(() => {
  setCheckbox(localStorage.getItem('Checkbox Value'))
},[]);

The JSX is

<div className="ui checkbox">
   <input type="checkbox" onChange={handleCheckboxChange} checked={checkbox}</input>
   <label>I agree to the Terms and Conditions: {checkbox}</label>
</div>

When the form renders the correct value (true, false) displays in the label but the checkbox renders checked no matter what the value Not sure what I am missing...

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

localStorage always returns strings, and since "false" (string) is a truthy value, your checkbox will be always checked.

Change your code to be:

useEffect(() => { 
  setCheckbox(JSON.parse(localStorage.getItem('Checkbox Value') || 'false'))
},[]);
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda