Skip to content

Commit

Permalink
Handle document.fonts not being define
Browse files Browse the repository at this point in the history
fixes #368
  • Loading branch information
ArnaudRinquin committed Apr 14, 2023
1 parent ab4c1ec commit 50b9a64
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ function useListener<
React.useLayoutEffect(() => {
const handler: typeof listener = (ev) => latestListener.current(ev);

// might happen if document.fonts is not defined, for instance
if (!target) {
return;
}

target.addEventListener(type, handler);
return () => target.removeEventListener(type, handler);
}, []);
Expand Down

0 comments on commit 50b9a64

Please sign in to comment.