AsyncStorage

AsyncStorage is an unencrypted, asynchronous, persistent, key-value storage system that is global to the app. It should be used instead of LocalStorage.

It is recommended that you use an abstraction on top of AsyncStorage instead of AsyncStorage directly for anything more than light usage since it operates globally.

npm i react-native-async-storage

setItem()

const data ={ uid:123,name:'This is my Name'}

const userData = await AsyncStorage.setItem('userData',data.uid)
or
const userData = await AsyncStorage.setItem('userData',JSON.stringify(datareac))

getItem()

const handleAsyncStorage=async()=>{
    const data = await AsyncStorage.getItem('userId')
    console.log(data,'data in handle Async')
}

clear()

const handleClear=async()=>{
    const data = await AsyncStorage.clear()
}

Last updated

Was this helpful?