Skip to content

Commit

Permalink
Fix flow error in useEvent
Browse files Browse the repository at this point in the history
  • Loading branch information
necolas committed Apr 20, 2021
1 parent 84fd278 commit 4e77aeb
Showing 1 changed file with 6 additions and 10 deletions.
16 changes: 6 additions & 10 deletions packages/react-native-web/src/modules/useEvent/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export default function useEvent(
): AddListener {
const targetListeners = useStable(() => new Map());

let addListener = useStable(() => {
const addListener = useStable(() => {
const addEventListener = createEventHandle(event, options);
return (target: EventTarget, callback: Callback) => {
const removeTargetListener = targetListeners.get(target);
Expand All @@ -50,16 +50,12 @@ export default function useEvent(

useLayoutEffect(() => {
return () => {
if (addListener != null) {
targetListeners.forEach((removeListener) => {
removeListener();
});
targetListeners.clear();
}
addListener = null;
targetListeners.forEach((removeListener) => {
removeListener();
});
targetListeners.clear();
};
}, [addListener]);
}, []);

// $FlowFixMe
return addListener;
}

0 comments on commit 4e77aeb

Please sign in to comment.