简体   繁体   中英

How to save item of FlatList in AsyncStorage react native?

i have a Flatlist that the data loaded from state. what i wan to do this when i click to a heart Icon that item addToWishlist using AsynStorage

i dont have any idea in my AddToWishList() function can anyone please help??

If you want to save the entire item object, AddToWishList should pass back the id from where it's being called.

import { AsyncStorage } from 'react-native';

AddToWishList = async (id) => {
  let itemToSave = JSON.Stringify(...dataArrayOfItems.filter(item => item.id === id))
  try {
   await AsyncStorage.setItem(id: itemToSave) 
    }
   catch (error) {
        //error saving data
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM