This package has been deprecated

Author message:

Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.

@stefanoruth/react-helpers
TypeScript icon, indicating that this package has built-in type declarations

1.0.27 • Public • Published

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

Readme

Keywords

none

Package Sidebar

Install

npm i @stefanoruth/react-helpers

Weekly Downloads

1

Version

1.0.27

License

MIT

Unpacked Size

26.3 kB

Total Files

20

Last publish

Collaborators

  • stefanoruth