Created
March 25, 2024 15:44
-
-
Save 8mist/b9458e5a2d442c94bb6b96157b137428 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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