diff --git a/packages/automerge-repo-react-hooks/src/useDocument.ts b/packages/automerge-repo-react-hooks/src/useDocument.ts index 4e50bd9e7..d2448816b 100644 --- a/packages/automerge-repo-react-hooks/src/useDocument.ts +++ b/packages/automerge-repo-react-hooks/src/useDocument.ts @@ -44,8 +44,11 @@ export function useDocument(id?: AnyDocumentId) { const onChange = (h: DocHandleChangePayload) => setDoc(h.doc) handle.on("change", onChange) + const onDelete = () => setDoc(undefined) + handle.on("delete", onDelete) const cleanup = () => { handle.removeListener("change", onChange) + handle.removeListener("delete", onDelete) } return cleanup