简体   繁体   中英

Fetching data from Firebase in React Native

I came across a map in Firebase. I have done the following structure in Firestore.

在火力基地

I want to read the state whether it is liked or not, corresponding to the user uid -

   onLike() {
     let list = this.props.list

     let uid = this.state.user.uid

     list.uid.liked = !list.uid.liked

     list.likes = list.uid.liked ? list.likes + 1 : list.likes - 1

     this.props.updateList(list);
   }

I think there is a mistake calling the user uid itself, I receive the error saying can't find variable and undefined object, please educate on the same.

Hi finally i figured out how to do it but modified a little,changed the write method as value itself not as map function,thanks to a javascript forum, the final code is as follows

  onLike(){


  let uid = this.state.user.uid;

  let list = this.props.list

  var liked = uid +'liked'

  list[liked] = !list[liked]

  list.likes = list[liked] ? list.likes + 1 : list.likes - 1

  this.props.updateList(list);
  };

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM