how to store array into react native local storage

Solutions on MaxInterview for how to store array into react native local storage by the best coders in the world

showing results for - "how to store array into react native local storage"
Alyssia
14 Nov 2020
1var myArray = ['one','two','three'];
2
3try {
4  await AsyncStorage.setItem('@MySuperStore:key', JSON.stringify(myArray));
5} catch (error) {
6  // Error saving data
7}
8
9try {
10  const myArray = await AsyncStorage.getItem('@MySuperStore:key');
11  if (myArray !== null) {
12    // We have data!!
13    console.log(JSON.parse(myArray));
14  }
15} catch (error) {
16  // Error retrieving data
17}
18