Skip to content

useDeleteDocument Hook

useDeleteDocument hook is used to delete a document in Firestore. A very simple example would be:

const docRef = doc(firestore, "collectionName", "docId");
const { state, dispatch, error } = useDeleteDocument(docRef);
const docRef = await dispatch();


Nothing is done until you use dispatch returned by useDeleteDocument hook.


Do not use dispatch in parallel as it will cause race conditions.

Input Parameters

Input parameters for useDeleteDocument hook is as follows:

Name Type Description Required Default Value
reference firebase/firestore/DocumentReferen Reference to a document in Firestore. -

Return Type

useDeleteDocument hook returns an object with properties as below:

Name Type Description
state "ready" or "loading" or "done" Whether this hook is ready to dispatch, currently dispatching or has dispatched successfully.
error firebase/FirebaseError or undefined The instance of error if any.
dispatch () => Promise<DocumentReference | undefined> A function to start adding a document.


Only firebase/FirebaseError is caught if any. error will not be an instance of another type.