“Async Storage React Native” Código de respuesta

asyncstorage.getallkeys

importData = async () => {
  try {
    const keys = await AsyncStorage.getAllKeys();
    const result = await AsyncStorage.multiGet(keys);

    return result.map(req => JSON.parse(req)).forEach(console.log);
  } catch (error) {
    console.error(error)
  }
}
Dark Dormouse

AsyncStorage React Native

yarn add @react-native-async-storage/async-storage // install by yarn
npm i @react-native-async-storage/async-storage // install by npm

// import
import AsyncStorage from '@react-native-async-storage/async-storage';


await AsyncStorage.setItem('@storage_Key', "value") // for store item
await AsyncStorage.removeItem('@storage_Key', "value") // for remove item
Bored Buzzard

Cómo instalar AsyncStorage en React Native

npm i @react-native-community/async-storage
Wicked Wren

npm react-nativo-async-storage

npm install @react-native-async-storage/async-storage
MAKSTYLE119

React Storage Native Storage

npm install react-native-storage
npm install @react-native-community/async-storage
Wandering Wren

Async Storage React Native


import AsyncStorage from '@react-native-async-storage/async-storage';
// store item
export const storeData = async (key, value) => {		
  try {
    await AsyncStorage.setItem(key, value);
    return {
        success: true
    }
  } catch (error) {
    return {
        success: false,
        error
    }
  }
}
// get item
export const getData = async (key) => {
  try {
    const value = await AsyncStorage.getItem(key)
    return {
        success: true,
        value
    }
  } catch(error) {
    return {
        success: false,
        error
    }
  }
}


export default {
    getData,
    storeData
}
Hamza javed

Respuestas similares a “Async Storage React Native”

Preguntas similares a “Async Storage React Native”

Más respuestas relacionadas con “Async Storage React Native” en JavaScript

Explore las respuestas de código populares por idioma

Explorar otros lenguajes de código