Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

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
Comment

how to install asyncstorage in react native

npm i @react-native-community/async-storage
Comment

react native asyncstorage getItem example

getMyObject = async () => {
  try {
    const jsonValue = await AsyncStorage.getItem('@key')
    return jsonValue != null ? JSON.parse(jsonValue) : null
  } catch(e) {
    // read error
  }

  console.log('Done.')

}
Comment

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
}
Comment

react native asyncstorage setItem example

setObjectValue = async (value) => {
  try {
    const jsonValue = JSON.stringify(value)
    await AsyncStorage.setItem('key', jsonValue)
  } catch(e) {
    // save error
  }

  console.log('Done.')
}
Comment

react native asyncstorage getItem example

getMyStringValue = async () => {
  try {
    return await AsyncStorage.getItem('@key')
  } catch(e) {
    // read error
  }

  console.log('Done.')

}
Comment

react native asyncstorage setItem example

setStringValue = async (value) => {
  try {
    await AsyncStorage.setItem('key', value)
  } catch(e) {
    // save error
  }

  console.log('Done.')
}
Comment

react native asyncstorage getItem

static getItem(key: string, [callback]: ?(error: ?Error, result: ?string) => void): Promise
Comment

react native asyncstorage setItem

static setItem(key: string, value: string, [callback]: ?(error: ?Error) => void): Promise
Comment

PREVIOUS NEXT
Code Example
Javascript :: javascript escape html string 
Javascript :: return longest string from array 
Javascript :: change name of html element javascript 
Javascript :: angular output 
Javascript :: charcodeat vs codepointat 
Javascript :: javascript add spaces to string 
Javascript :: text and icon on same line react native 
Javascript :: https with express 
Javascript :: javascript redirect page 
Javascript :: javascript redirect function 
Javascript :: redirect to homepage javascript 
Javascript :: disable right click using jquery 
Javascript :: jquery modal close 
Javascript :: javascript parentnode 
Javascript :: linking in react native 
Javascript :: clear canvas 
Javascript :: Error: [ProtectedRoute] is not a <Route component 
Javascript :: convert functoin with call back to promise 
Javascript :: JavaScript - How to get the extension of a filename 
Javascript :: javascript returned function and copy to clipboard 
Javascript :: js get all query string 
Javascript :: check if variable is undefined or null jquery 
Javascript :: how to take a input video 
Javascript :: get current directory vbscript 
Javascript :: lodash find object in array 
Javascript :: node js split data 
Javascript :: js export as name 
Javascript :: javascript is JSON string valid 
Javascript :: how to get back image and front text in react native 
Javascript :: inarray javascript 
ADD CONTENT
Topic
Content
Source link
Name
2+7 =