Skip to content

Commit

Permalink
fix: correct memo
Browse files Browse the repository at this point in the history
  • Loading branch information
therealparmesh committed Jan 22, 2020
1 parent 5af8b77 commit 549c5e5
Showing 1 changed file with 16 additions and 17 deletions.
33 changes: 16 additions & 17 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,20 @@ export const useHovering = ({ enterDelay, exitDelay } = {}) => {
[enterDelay, exitDelay],
);

const getTargetProps = React.useCallback(
({
const getTargetProps = React.useMemo(() => {
const makeMemo = value => {
return memoizeOne(callback => {
return e => {
changeHoverState(value);

if (callback) {
return callback(e);
}
};
});
};

return ({
ref: resolvableRef,
tabIndex,
onMouseEnter,
Expand All @@ -46,18 +58,6 @@ export const useHovering = ({ enterDelay, exitDelay } = {}) => {
onFocus,
onBlur,
} = {}) => {
const makeMemo = value => {
return memoizeOne(callback => {
return e => {
changeHoverState(value);

if (callback) {
return callback(e);
}
};
});
};

return {
ref: resolvableRef ? mergeRefs(ref, resolvableRef) : ref,
tabIndex: tabIndex || 0,
Expand All @@ -67,9 +67,8 @@ export const useHovering = ({ enterDelay, exitDelay } = {}) => {
onFocus: makeMemo(true)(onFocus),
onBlur: makeMemo(false)(onBlur),
};
},
[changeHoverState],
);
};
}, [changeHoverState]);

React.useEffect(() => {
const listener = e => {
Expand Down

0 comments on commit 549c5e5

Please sign in to comment.