Reputation: 101
I want to create a shopping cart. I use this code to save some data like username
. Now I want to save product ID
and Count
in an array in AsyncStorage
.
(I use expo.)
How can I do that?
_save_user = async () => {
await SecureStore.setItemAsync('username', parseInt(this.state.Username).toString());
};
Please tell me if you have some better idea.
Upvotes: 1
Views: 596
Reputation: 142
you can try something like this:
var item1 = {itemCode:"10101010", quantity:"500", anythingElse:"this"};
var item2 = {itemCode:"10102020", quantity:"42", anythingElse:"is"};
var item3 = {itemCode:"10103030", quantity:"2", anythingElse:"something"};
var yourArray = [item1,item2,item3];
_save_array = async () => {
await SecureStore.setItemAsync('yourKey', JSON.stringify(yourArray));
};
Upvotes: 3