Skip to content

Commit

Permalink
useDocument listen to delete events
Browse files Browse the repository at this point in the history
  • Loading branch information
joshuahhh committed Mar 10, 2024
1 parent 5977b9d commit ef122f7
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions packages/automerge-repo-react-hooks/src/useDocument.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,11 @@ export function useDocument<T>(id?: AnyDocumentId) {

const onChange = (h: DocHandleChangePayload<T>) => 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
Expand Down

0 comments on commit ef122f7

Please sign in to comment.