React Native

Expo - AsyncStorage

크런키스틱 2023. 6. 19. 18:21
728x90
AysncStorage란?
암호화 되지 않은 비동기적인 데이터를 관리하는 Key-Value 저장 시스템
앱 전역에서 사용할 수 있으며, LocalStorage 대신 사용

 

AsyncStroage 특징은 다음과 같다.

  1. 비동기(async / await)
  2. 문자열만 저장가능
  3. 앱 전체에 적용
  4. 암호화 x
  5. 영구 저장

1. 설치

yarn add @react-native-async-storage/async-storage

 

2. 데이터 저장

const setItem = async () => {
	await AsyncStorage.setItem(key, value);
}

 

3. 데이터 가져오기

const getItem = async () => {
	await AsyncStorage.getItem(key)
}

 

4. 데이터 삭제

const removeItem = async () => {
	await AsyncStorage.removeItem(key)
}
728x90