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

110
Views
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 answers
Answer question

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 Report

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 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!