I have created a small react app that you can type in a title of book and the author name, and it displays the list under below the form, also it stores in firebase database. If you want to delete it you can delete it frontend, however I have trouble with deleting it in my firebase database because I'm not sure how to dynamically refer the doc id. If I provide the id in the code, it's able to delete this particular id, but the user can't provide the id at frontend. Hoping someone help me out, thanks!
import React, {useContext} from 'react'
import {BookContext} from '../contexts/BookContext'
import firebase from '../config/fbConfig'
const BookDetails = ({bookProp}) => {
const {actionDispatch} = useContext(BookContext)
const handleOnClick = () => {
actionDispatch({type: "REMOVE_BOOK", id: bookProp.id})
firebase.firestore().collection('books').doc(id).delete()
.then(()=>{console.log("successfully deleted! ")})
.catch((error)=>{ console.log("Error removing document:", error)})
}
return(
<div>
{
<li onClick={handleOnClick}>
<div className="title">{bookProp.title}</div>
<div className="author">{bookProp.author}</div>
</li>
}
</div>
)
}
export default BookDetails
data()
property holding the data of your query and anid
property which gives you the uid assigned by firebase for that document. If you posted your query to get the document, I'd be able to show you how to get the uid.