I want to save houses in an array using AsyncStorage. Each array element represents a house Object. And each house object has a latitude, longitude and a house number. I am not sure how to go about representing this. It seems to me that AsyncStorage is not well-suited for saving dynamic objects that can be updated programmatically. I want to be able to add more houses and delete some houses. Basically what I am trying to do is bookmark some houses and delete them from the bookmarks when the user clicks. Can anyone help ?
相关问题
- React Native Inline style for multiple Text in sin
- How to get the maximum of more than 2 numbers in V
- Faster loop: foreach vs some (performance of jsper
- Convert Array to custom object list c#
- pick a random item from a javascript array
相关文章
- Numpy matrix of coordinates
- Why do we have to call `.done()` at the end of a p
- PHP: Can an array have an array as a key in a key-
- Remove expo from react native
- Accessing an array element when returning from a f
- How can I convert a PHP function's parameter l
- How to make a custom list deserializer in Gson?
- Recursively replace keys in an array
AsyncStorage is absolutely perfect for this.
Starting with the structure of your houses, I would create an Array which stores objects representing an individual house.
Saving to AsyncStorage
When you want to write your collection to
AsyncStorage
, you would do so like this:You can also use
async/await
if your project is set up to support it.Reading from AsyncStorage
Reading your collection back from
AsyncStorage
is simply done via:You could set the response in your state, do as you please.
Deleting a specific house
This depends entirely on how you set your app up. Are you going to
map
through each house and create a list component for example?(Sorry about losing the border on the right)
If so, you could:
Then create a
deleteHouse
function which will handle it.And finally a
saveHouses
to sync it back to AsyncStorage. The function will clear AsyncStorage and then save the new houses.You need a Sqlite alternative like Realm, it's free, fast and easy to code, with this you will save tons of hours of work, also as you need, you can make queries, update and delete objects.