10.10.2019 Views

3-React Native for beginners - By Dhanraj Acharya

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

ecause A remained mounted the whole time. To overcome this, we have to use lifecycle<br />

events provided by react navigation.<br />

v0.3.0<br />

Goals: How to store data locally.<br />

Every native application needs to store data such as user status, logged in status, app configuration etc. We can<br />

use SecureStore, AsyncStorage, SQLite, and Realm. This are most widely and easy to use services.<br />

Realm is very famous and used widely but you have to per<strong>for</strong>m expo eject to use it so we won’t<br />

be discussing it here. But it is useful to know about such tool so you may use it in future.<br />

SecureStore and AsyncStorage both are key-value storage system. The only difference between them is the way they<br />

store the data. SecureStore encrypts the data while AsyncStorage stores it in plain text.<br />

We won’t be using SecureStore or AsyncStorage. We will only use SQLite in our application but I<br />

have mentioned them here because they are very useful and easy to use.<br />

SecureStore<br />

iOS: Values are stored using the keychain services as kSecClassGenericPassword. iOS has the additional option of<br />

being able to set the value's kSecAttrAccessible attribute, which controls when the value is available to be fetched.<br />

Android: Values are stored in SharedPreferences, encrypted with Android's Keystore system.<br />

we can use below methods to manipulate the data.<br />

SecureStore.getItemAsync(key)<br />

SecureStore.setItemAsync(key,value)<br />

SecureStore.deleteItemAsync(key)<br />

For more in<strong>for</strong>mation, check out official SecureStore docs.<br />

AsyncStorage<br />

It has the similar API as SecureStore. we mainly use below methods,<br />

AsyncStorage.getItem(key)<br />

AsyncStorage.setItem(key, value)<br />

AsyncStorage.removeItem(key)<br />

For more methods, please check the official expo docs.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!