Storing application data

Now, let's shift our attention to storing data within a React Native application. The AsyncStorage API works the same on both iOS and Android platforms. You would use this API for applications that don't require any network connectivity in the first place, or to store data that's eventually synchronized using an API endpoint once a network becomes available.

Let's look at some code that allows the user to enter a key and a value, and then stores them:

import React, { Component } from 'react'; import { AppRegistry, Text, TextInput, View, ListView, AsyncStorage, } from 'react-native'; import { fromJS } from 'immutable'; import styles from './styles'; import Button from './Button'; class StoringData extends Component { // The ...

Get React and React Native now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.