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

236
Views
Get data stored in AsyncStorage instantly without async/await(promise)

config.js

AsyncStorage.getItem("storedValue").then(value=>{
//return data based on the value from asyncStorage storage
 if(value==="value1"){
  return {
   text:"text1",
   number:"number1"
  }
 }
 else if(value==="value2"){
  return {
   text:"text2",
   number:"number2"
  }
 }
})

index.js

import config from "./config"
//I have to use data from config file here
console.log(config.text) //->getting error
//The problem is that, since fetching from AsyncStorage is asynchronous, data from config is not yet available here


//I have tried SyncStorage npm package for react native. It loads all the asyncStored values into memory upon calling
await SyncStorage.init() //-> called on app initialisation

//And can be used later in place of AsyncStorage.getItem(""), which returns the value directly instead of promise
const value=SyncStorage.get("storedValue")

But the problem is, I am accessing the config in index.js(which is the starting file for a react-native project). And I have to initialise SyncStorage here, which is again asynchronous, which means the config file will get loaded before init() happens.

What I am expecting is:

  1. get the value stored in local storage instantly without async/await in index.js OR
  2. In the app, I will have a button to restart the app. But, should be able to pass a value during the restart, which can be used in config.js or index.js while the app loadsOR
  3. Or use any other package for deep-linking or something like that, so that on app restarting app using deep-link, the value passed should be accessible. It has to work for both android and iOS

Changes that are not possible:

  1. Cannot make any other file other than index.js as starting file because, many other project packages are being initialized here, and in fact, the stored value we are trying to access needs to be passed to these packages while initializing.

Thank you.

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

0

Please explain a little further...

Summarising what I understand from your question:

  • you want to read some value from async storage right away in index
  • you tried using synch storage for the same
  • you cannot move your code from index because you parked everything there

Trying to untangle that here my answer:

  • it is not really best practice to put a lot of code in app.js or index.js so I would try to avoid that as much as possible

  • sync storage as well as redux are normally just available at runtime and often are loaded from the async storage

  • async storage needs time and thus also needs to be loaded either with a then promise look or await catch

--> If I was you I would use async storage as normal with await and introduce some sort of splash screen where you do the loading.

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!