Skip to content

Latest commit

 

History

History
16 lines (12 loc) · 385 Bytes

capture-click.md

File metadata and controls

16 lines (12 loc) · 385 Bytes

Capture Click

To log all clicks in React, use onClickCapture. It logs clicks in all child components.

export const LogClicks = ({ children }) => {

    const onClick = React.useCallback((e) => {
        // log clicks here, child click handlers fire after this global click handler
    }, [])

    return (
        <div onClickCapture={onClick}>{ children }</div>
    )
}