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

220
Vistas
Async storage not loading new fresh data, only displays data when I reload the app

I am working on an app, that is similar to a Todo App. I have a Two Screen's which are SecondScreen.jsand FirtScreen.js. In SecondScreen.js is a screen which saves the data. Then the user clicks a button, it goes to FirstScreen.js which is this code down below. When it goes to the FirstScreen.js it does not update (add the new data), but it stays the same. When I add one more time, it adds the previous that was just added. Which is one data behind.

Also, the keys = await AsyncStorage.getAllKeys() is missing one data, the data that is added.

Also, the keys.pop() is for to remove a key that I don't use but it is for updating the id.

  const [realData, setData] = useState([]);
  useEffect(() => {
  const unsubscribe = navigation.addListener('focus',() => {
    getData();
  });
  return unsubscribe;
 },[navigation]);

  const getData= async () => {
    let keys = []
    try {
      keys = await AsyncStorage.getAllKeys()
    } catch(e) {
      console.log("Fail")
    }
    let values  
    let data = []
    keys.pop()
    try {    
    values = await AsyncStorage.multiGet(keys)
  } catch(e) {    // read error  
  }  

  values.map(values => {
   let jsonData = JSON.parse(value)
    data.push({"title": jsonData.title,"date": jsonData.date, "task": jsonData.task, "id": jsonData.id}) 
  })
  setData(data)
  }
``
about 4 years ago · Juan Pablo Isaza
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