How do I delete a specific document within a collection on the firestore using react?
I looked here and on google but I didn't find anything intrinsically related.
I'm just managing to delete the document with index [0] from my collection.
this.state.idDoc recives all id documents.
If I just pass the .doc(idDoc) I get the following error:
FirebaseError: Function CollectionReference.doc() requires its first argument to be of type non-empty string, but it was: an array
What am I doing wrong? any help is welcome.
constructor(props) {
super(props);
this.state = {
idDoc: = [],
}
delete = () => {
let idDoc = this.state.idDoc;
firebase.firestore().collection("newPost").doc(idDoc[0]).delete()
.then(function() {
console.log("Document successfully deleted!");
}).catch(function(error) {
console.error("Error removing document: ", error);
});
}
html button
<div>
<button id="PostDelete" onClick={this.delete}> <ion-icon name="ellipsis-horizontal-sharp"> </ion-icon> </button>
</div>