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:
- create an async storage: https://react-native-async-storage.github.io/async-storage/docs/usage/
- use a state management system like redux which will save the states in a store for you
- write the data to a database like firebase and then retrieve it to display it