title: React+Firebase: How to add item to list data into firebase realtime database
body: <p>I'm using react and firebase real-time database. I want to create a list for each user. A list of id to later look for files in storage. In this case what is the best method to generate and add an id to list in database? (Not list of data, the data stored in the database is the list)</p>
  
  <p>So I have two methods in mind. I'll write in pseudo code</p>
  
  <pre><code>//Method 1
  //get id list
  receivedList = getKeyListFromDB()
  //generate ID
  newID = generateID()
  // append new id
  receivedList.append(newID)
  //set value with updated list
  updateDB(receivedList)
  
  //Method 2
  // Using the list provided by the firebase
  newRef = firebase.database().ref().child('pathToList').push()
  newRef.set({
        key: newRef.key
      })
  </code></pre>
  
  <p>I was going for method 1, but couldn't find a way to generate id. And retreiving the list to update it seemed inefficient. So I tried to find another method. But I can't find a good way to do this.</p>
  
  <p>Solution to add a value to list in database</p>
  
  <p>I have solved using transaction method. But if there is a way to solve by using <code>push</code> please do answer. </p>