ts-react-hooks
TypeScript icon, indicating that this package has built-in type declarations

1.0.0 • Public • Published

React hooks

Some useful react hooks

useOnEventOutside

const Screen = () => {
    const ref = useRef<HTMLDivElement>(null)

    useOnEventOutside('click', ref, () => {
        // clicked on an element which is not the div with text `Hello`
        // or it's descendant
    })

    return <div>
        <div></div>
        <div ref={ref}>Hello</div>
    </div>
}

useOnGlobalEvent

const Screen = () => {
    const ref = useRef<HTMLDivElement>(null)

    useOnGlobalEvent('click', () => {
        // clicked anywhere in the DOM
    })

    return <div>Hello</div>
}

Readme

Keywords

Package Sidebar

Install

npm i ts-react-hooks

Weekly Downloads

1

Version

1.0.0

License

MIT

Unpacked Size

12.5 kB

Total Files

12

Last publish

Collaborators

  • fingerartur