Home > Software engineering >  React Native save state even after app exits
React Native save state even after app exits

Time:04-01

How do I save text input state? I'm using <TextInput> and when user enter value the <Text> component contains that input (by React.useState())

But when I exit app the <Text> component contains default value.

How can I save the input even when the apps exits. And then it will show to state before closing.

Thank you.

I've tried overiting JSON file, using state, and I don't know what I'm doing wrong.

CodePudding user response:

If you want the data to persist after the app is closed, the data should be saved to a storage, for example async storage, and then retrieved later when you open the app again.

CodePudding user response:

you'll have to do one of these:

  1. create an async storage: https://react-native-async-storage.github.io/async-storage/docs/usage/
  2. use a state management system like redux which will save the states in a store for you
  3. write the data to a database like firebase and then retrieve it to display it
  • Related