Advertisement
karamarimo

firebase increment star count

Oct 28th, 2017
45
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. starBtnClick(value) {
  2.   this.addStar(value)
  3. }
  4.  
  5. addStar(uid) {
  6.   const myuid = this.state.userId
  7.   firebase.database().ref('/users/' + myuid + '/starred_users/').push().set({
  8.     starUserData: uid
  9.   }).then(function () {
  10.     return firebase.database().ref('users/' + uid + '/starCount').transaction(function(count) {
  11.       count += 1
  12.       return count
  13.     })
  14.   }).then(function (committed) {
  15.     if (committed) {
  16.         // 表示を更新
  17.     }
  18.   })
  19. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement