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

237
Vistas
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 Respuestas
Responde la pregunta

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