Skip to content

Commit

Permalink
fix(usePointers): change some conditions
Browse files Browse the repository at this point in the history
  • Loading branch information
malkiii committed Nov 17, 2023
1 parent ab07133 commit c00896f
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion docs/guide/usePointers.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export default function Example() {

if (event.type === 'pointerdown') {
document.body.appendChild(pointer);
} else if (!list.includes(event)) {
} else if (!list.find(e => e.pointerId === event.pointerId)) {
pointer.remove();
}
});
Expand Down
4 changes: 2 additions & 2 deletions package/src/usePointers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,13 @@ export const usePointers = <T extends HTMLElement = HTMLDivElement>(
}, []);

const removePointer = useCallback((event: PointerEvent) => {
pointersList.current = pointersList.current.filter(e => e.pointerId === event.pointerId);
pointersList.current = pointersList.current.filter(e => e.pointerId !== event.pointerId);
}, []);

const handlePointerEvents = useCallback(
(event: PointerEvent) => {
if (event.type === 'pointerdown') addPointer(event);
if (['pointerup', 'pointercancel', 'pointerout'].includes(event.type)) removePointer(event);
if (['pointerup', 'pointercancel'].includes(event.type)) removePointer(event);

handler(event, pointersList.current);
},
Expand Down

0 comments on commit c00896f

Please sign in to comment.