1.1.3 • Published 2 years ago

@extended-lib/react-hooks v1.1.3

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

@extended-lib/react-hooks

NPM Version NPM Downloads NPM Dependents Build Coverage Types Tree Shaking

× DOCS × DISCORD ×


@extended-lib/react-hooks is a library of general-purpose React hooks built with care and SSR compatibility in mind.

Install

This one is pretty simple, everyone knows what to do:

npm i @extended-lib/react-hooks
# or
yarn add @extended-lib/react-hooks

As hooks was introduced to the world in React 16.8, @extended-lib/react-hooks requires - you guessed it - react and react-dom 16.8+. Also, as React does not support IE, @extended-lib/react-hooks does not do so either. You'll have to transpile your node-modules in order to run in IE.

Usage

This package provides three levels of compilation:

  1. Main, the /cjs folder — CommonJS modules, with ES5 lang level.
  2. ESM, the /esm folder — it is ES modules (browser compatible), with ES5 lang level.
  3. ESNext, the /esnext folder — it is ES modules (browser compatible), with ESNext lang level.

So, if you need the useMountEffect hook, depending on your needs, you can import in three ways (there are actually more, but these are the three most common):

// in case you need cjs modules
import { useMountEffect } from '@extended-lib/react-hooks';
// in case you need esm modules
import { useMountEffect } from '@extended-lib/react-hooks/esm';
// in case you want all the recent ES features
import { useMountEffect } from '@extended-lib/react-hooks/esnext';

Migrating from react-use

Coming from react-use? Check out our migration guide.

Hooks list

  • Callback

  • Lifecycle

  • State

    • useDebouncedState — Like useSafeState but its state setter is debounced.
    • useMap — Tracks the state of a Map.
    • useMediatedState — Like useState, but every value set is passed through a mediator function.
    • usePrevious — Returns the value passed to the hook on previous render.
    • usePreviousDistinct — Returns the most recent distinct value passed to the hook on previous render.
    • useRafState — Like React.useState, but state is only updated within animation frame.
    • useSafeState — Like useState, but its state setter is guarded against sets on unmounted component.
    • useSet — Tracks the state of a Set.
    • useToggle — Like useState, but can only become true or false.
    • useThrottledState — Like useSafeState but its state setter is throttled.
    • useValidator — Performs validation when any of provided dependencies has changed.
  • Navigator

  • Miscellaneous

    • useSyncedRef — Like useRef, but it returns immutable ref that contains actual value.
  • Side-effect

  • Sensor

    • useIntersectionObserver — Observe changes in the intersection of a target element with an ancestor element or with a top-level document's viewport.
    • useMeasure — Uses ResizeObserver to track element dimensions and re-render component when they change.
    • useMediaQuery — Tracks the state of CSS media query.
    • useResizeObserver — Invokes a callback whenever ResizeObserver detects a change to target's size.
    • useScreenOrientation — Checks if screen is in portrait or landscape orientation and automatically re-renders on orientation change.
  • Dom

1.1.3

2 years ago

1.1.2

2 years ago

1.1.1

2 years ago

1.1.0

2 years ago

13.4.0

2 years ago

13.3.0

2 years ago

13.2.0

2 years ago