“Async Storage React Native” Kod odpowiedzi

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

Jak zainstalować asyncstorage w React Native

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

NPM React-Native-Async-Storage

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

React 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

Odpowiedzi podobne do “Async Storage React Native”

Pytania podobne do “Async Storage React Native”

Więcej pokrewnych odpowiedzi na “Async Storage React Native” w JavaScript

Przeglądaj popularne odpowiedzi na kod według języka

Przeglądaj inne języki kodu