Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

221
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda