Programming/React Native

[React Native] AsyncStorage란? / 사용법

MOONCO 2022. 6. 22. 19:57

AsyncStorage란?

React Native의 키-값 형태의 데이터 영구 저장소

- 문자열만 저장가능
- 앱 전체에 적용됨
- 암호화 되지 않음
- 비동기 방식으로 동작
- 영구 저장 ( 지울때까지 보존 )
- 브라우저의 LocalStorage와 비슷하다. ( 브라우저는 동기식 )

 

AsyncStorage에 데이터 저장하기

AsyncStorage.setItem(키, 값)
    .then(() => console.log('저장 성공'))
    .catch(e => console.log('오류', e.message))
    
/*
  AsyncStorage: {
    키 : 값
  }
*/

 

AsyncStorage에서 데이터 가져오기

AsyncStorage.getItem(키)
    .then(() => console.log('가져옴'))
    .catch(e => console.log('오류', e.message))

 

반응형