Skip to content

Instantly share code, notes, and snippets.

@8mist
Created March 25, 2024 15:44
Show Gist options
  • Save 8mist/b9458e5a2d442c94bb6b96157b137428 to your computer and use it in GitHub Desktop.
Save 8mist/b9458e5a2d442c94bb6b96157b137428 to your computer and use it in GitHub Desktop.
import {
forwardRef,
useCallback,
type ComponentPropsWithoutRef,
type ElementRef,
type MouseEventHandler,
} from 'react';
const PropagationStopper = forwardRef<ElementRef<'div'>, ComponentPropsWithoutRef<'div'>>(
({ children, ...props }, forwardedRef) => {
const handleClick: MouseEventHandler<HTMLDivElement> = useCallback((event) => {
event.stopPropagation();
}, []);
return (
<div ref={forwardedRef} onClick={handleClick} {...props}>
{children}
</div>
);
},
);
PropagationStopper.displayName = 'PropagationStopper';
export default PropagationStopper;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment