Local Data Storage with React Native

Asked

Viewed 1,981 times

1

I am creating an application that needs to store some data locally These are simple examples:

"DATE"
"Local"
"Moisture"
etc..

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

1 answer

1


Take a look at the API Asyncstorage. 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 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 what is available.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.