FLYAI4 / ArtFront-ReactNative

ํ”„๋กœ์ ํŠธ Frontend repo ์ž…๋‹ˆ๋‹ค.
1 stars 1 forks source link

[Frontend] AsyncStorage Research #19

Closed heehminh closed 9 months ago

heehminh commented 9 months ago

๐Ÿ“Œ Description

AsyncStorage ์‚ฌ์šฉ๋ฒ• ๋ฆฌ์„œ์น˜


๐ŸŽˆ Goal

$\tiny{๊ตฌ์ฒด์ ์ธ\ ์‚ฐ์ถœ๋ฌผ์„\ ํฌํ•จํ•œ\ ๋ชฉํ‘œ๋ฅผ\ ์ž‘์„ฑํ•ด์ฃผ์„ธ์š”.}$


โœ๏ธ Todo

$\tiny{๋ชฉํ‘œ\ ๋‹ฌ์„ฑ์„\ ์œ„ํ•ด\ ํ•ด์•ผํ• \ ์ผ์„\ ์„ธ๋ถ€์ ์œผ๋กœ\ ์ž‘์„ฑํ•ด์ฃผ์„ธ์š”.}$

heehminh commented 9 months ago

์›น์„ ๊ฐœ๋ฐœํ•  ๋•Œ ๋ฐ์ดํ„ฐ๋ฅผ ๊ฐ„๋‹จํ•˜๊ฒŒ ์˜๊ตฌ์ ์œผ๋กœ (?) ์ €์žฅํ•˜๋ ค๋ฉด Local Storage๋ฅผ ์‚ฌ์šฉํ•˜๋Š”๋ฐ, ์•ฑ์„ ๊ฐœ๋ฐœํ•  ๋•Œ๋Š” AsyncStorage๋ฅผ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋‹ค. ๋ณดํ†ต ์œ ์ € ์ •๋ณด๋‚˜ ํ† ํฐ๋“ค์„ ์ €์žฅํ•˜๋Š”๋ฐ ์‚ฌ์šฉ๋œ๋‹ค.

1. ๋ชจ๋“ˆ ์„ค์น˜

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

2. ์‚ฌ์šฉ๋ฒ•

react-native-async-storage docs

Storing string value

const storeData = async (value) => {
  try {
    await AsyncStorage.setItem('@storage_Key', value)
    } catch (e) {
      // saving error
  }
}

Storing object value

const storeData = async (value) => {
  try {
    const jsonValue = JSON.stringfy(value)
    await AsyncStorage.setItem('@storage_Key', jsonValue)
    } catch (e) {
      // saving error
  }
}