1.0.27 • Published 4 years ago

@stefanoruth/react-helpers v1.0.27

Weekly downloads
-
License
MIT
Repository
github
Last release
4 years ago

React Helpers

A small set of components to help bulding simpler code.

version license size

Features

  • Scroll lock
  • Focus trap
  • Click away listener
  • Keyboard listiner
  • Simple Portals
  • ClassName builder
  • Config Builder
  • Interval Hook

Installation

yarn add @stefanoruth/react-helpers

or

npm install @stefanoruth/react-helpers --save

Basic usage

import { Portal, useScrollLockEffect, useTabFocus, useOnClickAway, useOnEscKey } from '@stefanoruth/react-helpers'

export const Modal: React.FunctionComponent<{ onClose: () => void }> = props => {
    const modalRef = React.useRef < HTMLDivElement > null

    useScrollLockEffect()

    useTabFocus(modalRef)

    useOnClickAway(modalRef, () => {
        props.onClose()
    })

    useOnEscKey(() => {
        props.onClose()
    })

    return (
        <Portal>
            <div ref={modalRef}>
                <button onClick={props.onClose}>Close</button>
                {props.children}
            </div>
        </Portal>
    )
}

Development

https://reactjs.org/warnings/invalid-hook-call-warning.html#duplicate-react

npm link example/node_modules/react

yarn dev

License

MIT

1.0.27

4 years ago

1.0.22

4 years ago

1.0.21

4 years ago

1.0.20

4 years ago

1.0.25

4 years ago

1.0.24

4 years ago

1.0.23

4 years ago

1.0.18

4 years ago

1.0.2

4 years ago

1.0.5

4 years ago

1.0.4

4 years ago

1.0.3

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago