sunnylqm / react-native-storage

local storage wrapper for both react-native and browser. Support size controlling, auto expiring, remote data auto syncing and getting batch data in one query.
MIT License
3.02k stars 268 forks source link

increase the count #205

Closed Q8hma closed 5 years ago

Q8hma commented 5 years ago

Hello i want to used this plugin but i have one issue

i want to increase count of items i add like first time it by default it save count 1 after i click add it make it 2 then 3 and like that

this my code but it not work

 addNewRow = () => {
storage.save({
  key: 'loginState', // Note: Do not use underscore("_") in key!
  data: {
    from: 'some other site',
    userid: 'some userid',
    token: 'some token',
    count:0
  },

  // if expires not specified, the defaultExpires will be applied instead.
  // if set to null, then it will never expire.
  expires: 1000 * 3600
});
    this.setState({statusdata: "new"});

};

  upDateRow = () => {
storage.save({
  key: 'loginState', // Note: Do not use underscore("_") in key!
  data: {
    from: 'some other site',
    userid: 'some userid',
    token: 'some token',
    count:+1
  },

  // if expires not specified, the defaultExpires will be applied instead.
  // if set to null, then it will never expire.
  expires: 1000 * 3600
});
    this.setState({statusdata: "update"});

};

any help ??

sunnylqm commented 5 years ago

// always use a variable if you want to record something
// storage is not to replace variables
count = 0;  
addNewRow = () => {
   storage.save({ key: 'rowCount', data: 0 });
   this.count = 0;  
   this.setState({ statusdata: 'new' });
}
updateRow = () => {
   this.count += 1;
   storage.save({ key: 'rowCount', data: this.count });
   this.setState({ statusdata: 'update' });
}
Q8hma commented 5 years ago

thanks bro , you save me with this plugin