Skip to content

Instantly share code, notes, and snippets.

@owonwo
Last active October 6, 2025 16:15
Show Gist options
  • Select an option

  • Save owonwo/d55df3b275e1f425829dda00980bd384 to your computer and use it in GitHub Desktop.

Select an option

Save owonwo/d55df3b275e1f425829dda00980bd384 to your computer and use it in GitHub Desktop.
DebugClick Component for React
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