Last active
October 6, 2025 16:15
-
-
Save owonwo/d55df3b275e1f425829dda00980bd384 to your computer and use it in GitHub Desktop.
DebugClick Component for React
This file contains hidden or 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 { Slot } from "@radix-ui/react-slot" | |
| import { rootLogger } from "@/lib/logger" | |
| /** | |
| * @description - Logs input to the console for debugging. Hold SHIFT and Click | |
| * @param props | |
| * @returns | |
| */ | |
| export function DebugClick(props: { | |
| disabled?: boolean | |
| input: () => unknown | |
| onClick?: (event: any) => void | |
| children: React.ReactNode | |
| ref?: React.RefObject<HTMLDivElement> | |
| }) { | |
| const { children, input: fn } = props | |
| const logger = rootLogger.withTag("DebugClick") | |
| if (props.disabled) return children | |
| return ( | |
| <Slot | |
| title="[Shift] + [Click] to see output in console" | |
| onClickCapture={(evt) => { | |
| console.log("holding shift", evt.shiftKey) | |
| if (evt.shiftKey === false) { | |
| return props.onClick?.(evt) | |
| } | |
| evt.preventDefault() | |
| evt.stopPropagation() | |
| logger.log(fn()) | |
| }} | |
| > | |
| {children} | |
| </Slot> | |
| ) | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment