L
L
LoveCode &Coffe2019-07-14 20:49:44
CRUD
LoveCode &Coffe, 2019-07-14 20:49:44

How to edit firebase data?

I figured out so far only how to add and delete data to the db and receive them, but how to change existing data using request?

class ApiService {
  constructor(baseUrl) {
    this.url = baseUrl
  }

 async createComputer(computer){
   try {
    const request = new Request(this.url + '/computers.json', {
      method: 'post',
      body: JSON.stringify(computer)
    })
    return useRequest(request)
   } catch (error){
     console.error(error)
   }
  }

  async fetchComputer() {
    try{

      const request = new Request(`${this.url}/computers.json`, {
        method: 'get'
      })
     return useRequest(request)

    } catch (error) {
      console.error(error)
    }
  }
}

this code send and receive data
const apiService = new ApiService('https://my-linkr.firebaseio.com/')

Answer the question

In order to leave comments, you need to log in

1 answer(s)
O
orbit070, 2019-07-14
@LoveCode &Coffe

To update / edit data, the put and patch methods are used there.
Put - if there is no record, it will create a new one, and if there is a record, it will overwrite all the data.
Patch - will add/remove/change data in a record without changing the record itself.
Examples

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question