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

117
Vistas
React Native setState issues using true false and null

I am trying to setState on something that may be true false or null. I am having issues and looking for a clean way to code

does not work

setFullCalendar(await AsyncStorage.getItem('@calendar') === 'true' || null ? true: false);

Works but I can not set if null

setFullCalendar(await AsyncStorage.getItem('@calendar') === 'true' ? true: false);

Works but not clean. (not clean because I have over 10 of these todo)

const checkStorage = await AsyncStorage.getItem('@calendar')
if(checkStorage == 'true'){
    setFullCalendar(true)
} else if (checkStorage !== null){
    setFullCalendar(true)
} else{
    setFullCalendar(false)
}
about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

Since it's only false if the value is null, just compare against that:

const checkStorage = await AsyncStorage.getItem('@calendar');
setFullCalendar(checkStorage !== null);
about 4 years ago · Juan Pablo Isaza Denunciar

0

You could use double negation to eliminate falsey values like null, undefined, false, "", etc... and get the right boolean result, keep in mind that empty objects, and empty arrays are truthy, not falsey values.

setFullCalendar(!!(await AsyncStorage.getItem('@calendar')));

or use the Boolean object to get the boolean result of that async action

setFullCalendar(Boolean(await AsyncStorage.getItem('@calendar')))
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