Local data storage with React Native

1

I'm creating an application that needs to store some data locally Examples are simple data:

"DATA"
 "Local"
 "Humidity"
etc.

As a reference it would be something like having a data file or rather a "localhost" database where I would save a series of basic application data. No connection to an API, or internet.

    
asked by anonymous 11.12.2018 / 17:01

1 answer

1

Take a look at the AsyncStorage API. Example:

import { AsyncStorage } from "react-native";

let data_object = {
  data: '2018-08-01',
  local: 'Rua ...',
  humidade: 40,
};

// Armazenando dados
await AsyncStorage.setItem('DATA_KEY', JSON.stringify(data_object));

// Recuperando dados
const data = await AsyncStorage.getItem('DATA_KEY');
  

In iOS, AsyncStorage is based on a native code that stores small values in a serialized dictionary and larger values in separate files. On Android, AsyncStorage uses RocksDB or SQLite based on whatever is available.

    
11.12.2018 / 18:15