Skip to content

Commit

Permalink
fix: check if ref exists
Browse files Browse the repository at this point in the history
  • Loading branch information
therealparmesh committed Jan 19, 2020
1 parent bda7d20 commit 7772017
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
@@ -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(
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 7772017

Please sign in to comment.