From 8526bbb967ceee2c1e9c5d6abf121df676a73e55 Mon Sep 17 00:00:00 2001 From: Dan Wood Date: Tue, 28 Dec 2021 23:30:46 +1000 Subject: [PATCH] Support default element when running in browser `global` is only defined in Node. `globalThis` will work for most users, but this workaround should work for all --- src/index.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/index.js b/src/index.js index 9707e97..86442e6 100644 --- a/src/index.js +++ b/src/index.js @@ -1,10 +1,12 @@ /* eslint-disable max-params */ import { useRef, useEffect } from 'react'; +const globalObject = typeof window === 'undefined' ? global : window + const useEventListener = ( eventName, handler, - element = global, + element = globalObject, options = {} ) => { const savedHandler = useRef();