Home > Mobile >  How to save the data while killing the App React native
How to save the data while killing the App React native

Time:05-10

I am trying to save the data through local storage during unmount phase. However, componentWillUnmount() doesn't support saving the local storage. Any alternative solution is available to save the data while killing the app.

CodePudding user response:

You can save the data using the AsyncStorage in react native: https://react-native-async-storage.github.io/async-storage/docs/usage

Just like localstorage, you can set value.

  await AsyncStorage.setItem('KEY', VALUE)

And get item like this:

const value = await AsyncStorage.getItem('KEY')

CodePudding user response:

If you want to just store some data when component unmount then you can use async storage but if you want store data when app got killed then you should handle this at native side (android/ios) with some background services.

  • Related