AsyncStorage.mergeItem()

static mergeItem(key, value, callback?)

Merges existing value with input value, assuming they are stringified json. Returns a Promise object. Not supported by all native implementations.

Example:

let UID123_object = {
 name: 'Chris',
 age: 30,
 traits: {hair: 'brown', eyes: 'brown'},
};

// need only define what will be added or updated
let UID123_delta = {
 age: 31,
 traits: {eyes: 'blue', shoe_size: 10}
};

AsyncStorage.setItem('UID123', JSON.stringify(UID123_object), () => {
  AsyncStorage.mergeItem('UID123', JSON.stringify(UID123_delta), () => {
    AsyncStorage.getItem('UID123', (err, result) => {
      console.log(result);
      // => {'name':'Chris','age':31,'traits':{'shoe_size':10,'hair':'brown','eyes':'blue'}}
    });
  });
});
doc_React_Native
2016-06-23 04:23:40
Comments
Leave a Comment

Please login to continue.