3

I want to make an app remember some data that a user puts in even after he turns off the phone (like auto-login). How can this be done in React Native? Or which libraries/components should I research?

3 Answers 3

8

If you want to do something like auto-login you should probably be using react-native-keychain so that you can store user credentials in the keychain on the device in a more secure way.

If you are looking to store a particular application state or other non sensitive data you could use react-native-simple-store which provides a really simple wrapper around AsyncStorage and takes care of the boilerplate JSON.stringify/JSON.parse that you need to do for objects and arrays.

Hope that helps!

Sign up to request clarification or add additional context in comments.

Comments

1

you can use flux stores, async store to store the current state in store, and re-route based on the store

can use componentWillMount mixing for setting up state before rendering view. for e.g.:

componentWillMount() {
    LocalStorage.bootstrap(() => this.setState({bootstrapped: true}));
},

you can refer https://github.com/brentvatne/flux-util/blob/master/lib/flux-util.js for example.

Comments

1

You can use AsyncStorage bundled with react-native. It creates key value pairs

AsyncStorage.setItem("key", "value").done() // both key and value have to be strings AsyncStorage.getItem("key").then((value) =>{}).done()

You can check the documentation for more options https://facebook.github.io/react-native/docs/asyncstorage.html#content

1 Comment

Note that this is unencrypted and shouldn't be used for sensitive user data

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.