Skip to content

Commit

Permalink
Replace isScrolling state with ref
Browse files Browse the repository at this point in the history
  • Loading branch information
kacper-mikolajczak committed Sep 26, 2023
1 parent 0dbb737 commit d1c0a27
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/components/Hoverable/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ function mapChildren(children, callbackParam) {

function InnerHoverable({disabled, onHoverIn, onHoverOut, children, shouldHandleScroll}, outerRef) {
const [isHovered, setIsHovered] = useState(false);
const [isScrolling, setIsScrolling] = useState(false);

const isScrolling = useRef(false);
const isHoveredRef = useRef(false);
const ref = useRef(null);

Expand All @@ -38,12 +38,12 @@ function InnerHoverable({disabled, onHoverIn, onHoverOut, children, shouldHandle

isHoveredRef.current = hovered;

if (shouldHandleScroll && isScrolling) {
if (shouldHandleScroll && isScrolling.current) {
return;
}
setIsHovered(hovered);
},
[disabled, shouldHandleScroll, isScrolling],
[disabled, shouldHandleScroll],
);

useEffect(() => {
Expand All @@ -60,7 +60,7 @@ function InnerHoverable({disabled, onHoverIn, onHoverOut, children, shouldHandle
}

const scrollingListener = DeviceEventEmitter.addListener(CONST.EVENTS.SCROLLING, (scrolling) => {
setIsScrolling(scrolling);
isScrolling.current = scrolling;
if (!scrolling) {
setIsHovered(isHoveredRef.current);
}
Expand Down

0 comments on commit d1c0a27

Please sign in to comment.