From 7772017349225f77d19f88140ef82338091708ac Mon Sep 17 00:00:00 2001 From: Parmesh Krishen Date: Sun, 19 Jan 2020 10:13:43 -0600 Subject: [PATCH] fix: check if ref exists --- src/index.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/index.js b/src/index.js index ed2d33a..1894a93 100644 --- a/src/index.js +++ b/src/index.js @@ -1,7 +1,7 @@ import React from 'react'; export const useHovering = () => { - const ref = React.useRef(); + const ref = React.useRef(null); const [hovering, setHovering] = React.useState(false); const bind = React.useMemo( @@ -29,6 +29,10 @@ export const useHovering = () => { React.useEffect(() => { const listener = e => { + if (!ref.current) { + return; + } + const minX = ref.current.offsetLeft; const maxX = minX + ref.current.offsetWidth; const minY = ref.current.offsetTop;