Jonas
Jonas

Reputation: 261

How to set array of object inside async storage in react native

I am trying to set array of object inside async storage but I did not set it . Could someone please help me how to achieve this . Thanks

Code

  let joined = this.state.product.concat(product);
    this.props.setNotification(joined);
    AsyncStorage.setItem("count", joined);

Upvotes: 1

Views: 1158

Answers (1)

Guruparan Giritharan
Guruparan Giritharan

Reputation: 16334

The easiest way is to stringify the array and store it

AsyncStorage.setItem('count', JSON.stringify(joined));

You will have to parse the string when you retrieve it

const storedArray = await  AsyncStorage.getItem('count');
const array = JSON.parse(storedArray)

Upvotes: 1

Related Questions