24.0.4 • Published 3 months ago

@react-hookz/web v24.0.4

Weekly downloads
-
License
MIT
Repository
github
Last release
3 months ago

@react-hookz/web

NPM Version NPM Downloads NPM Dependents Build Coverage Types Tree Shaking

× DOCS × DISCORD × CHANGELOG ×


@react-hookz/web 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 @react-hookz/web
# or
yarn add @react-hookz/web

As hooks was introduced to the world in React 16.8, @react-hookz/web requires - you guessed it - react and react-dom 16.8+. Also, as React does not support IE, @react-hookz/web don't either.

Usage

This package distributed with ESNext language level and ES modules system. It means that depending on your browser target you might need to transpile it. Every major bundler provides a way to transpile node_modules fully or partially. Address your bundler documentation for more details.

You can import hooks two ways:

// from the root of package
import { useMountEffect } from '@react-hookz/web';
// or single hook directly
import { useMountEffect } from '@react-hookz/web/useMountEffect/index.js';

In case your bundler supports tree-shaking (most of modern does) - both variants are equal and only necessary code will get into your bundle. Direct hook imports should be considered otherwise.

Migrating from react-use

@react-hookz/web was built as a spiritual successor of react-use by one of its former maintainers.

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

Hooks list

  • Callback

  • Lifecycle

  • State

    • useControlledRerenderState — Like useState, but its state setter accepts an extra argument, that allows cancelling renders.
    • useCounter — Tracks a numeric value and offers functions for manipulating it.
    • useDebouncedState — Like useState but its state setter is debounced.
    • useFunctionalState — Like useState but instead of raw state, a state getter function is returned.
    • useList — Tracks a list and offers functions for manipulating it.
    • 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 renders.
    • useQueue — A state hook implementing FIFO queue.
    • useRafState — Like React.useState, but state is only updated within animation frame.
    • useRenderCount — Tracks component's render count including first render.
    • useSet — Tracks the state of a Set.
    • useToggle — Like useState, but can only be true or false.
    • useThrottledState — Like useState but its state setter is throttled.
    • useValidator — Performs validation when any of the provided dependencies change.
  • Navigator

    • useNetworkState — Tracks the state of the browser's network connection.
    • useVibrate — Provides vibration feedback using the Vibration API.
    • usePermission — Tracks the state of a permission.
  • Miscellaneous

    • useSyncedRef — Like useRef, but it returns an immutable ref that contains the actual value.
    • useCustomCompareMemo — Like useMemo but uses provided comparator function to validate dependency changes.
    • useDeepCompareMemo — Like useMemo but uses @react-hookz/deep-equal comparator function to validate deep dependency changes.
    • useHookableRef — Like useRef but it is possible to define handlers for getting and setting the value.
  • Side-effect

  • Sensor

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

    • useClickOutside — Triggers a callback when the user clicks outside a target element.
    • useEventListener — Subscribes an event listener to a target element.
    • useKeyboardEvent — Invokes a callback when a keyboard event occurs on the chosen target.
    • useWindowSize — Tracks the inner dimensions of the browser window.

Contributors

@wooldox/reservoir-kit-ui@beskar-labs/command-bar@beskar-labs/glimpse@beskar-labs/use-gamepad-events@beskar-labs/use-themeaidexa-open-dsraslib@rasreee/react-utils@infinitebrahmanuniverse/nolb-_react-h@textea/yodasjob-web-app@everything-registry/sub-chunk-764pwa-kit-bedrock@invexa/lib@immobiliarelabs/backstage-plugin-ldap-authrea11y-easy-form@jbcz/baseui-rich-text-editor@likec4/diagram@likec4/diagrams@luxmarket/ui@luma-health/ui-utils@mirohq/websdk-react-hooks@moser-inc/moser-labs-react@h5web/app@h5web/lib@gqty/react@haydenbleasel/command-bar@haydenbleasel/glimpse@haydenbleasel/use-gamepad-events@haydenbleasel/use-sticky@haydenbleasel/use-themereact-sync-boardreact-visual-novel@nftearth/reservoir-kit-uireact-glimpse@frontside/backstage-plugin-scaffolder-workflow@origin/reservoir-kit-ui@helms/weda-uisynapse-react-clienttrain-brain-uiyearn-lib-silent@reservoir0x/reservoir-kit-ui@sh-reservoir0x/reservoir-kit-ui@simwrapper/h5web-app@solace-labs/backstage-plugin-ep-devp-auth@snowball-tech/fractal@solq-ui/react@spear-ai/ui@recative/act-player@recative/ap-preview@recative/client-sdk@web-media/act-player@web-media/ap-preview@web-media/client-sdk@tuci/pro@techindicium/core-components@sk-web-gui/alert-banner@veecode-platform/core-components@veecode-platform/plugin-scaffolder@truvity/js-core__react-utils@zoolabs/ui@vrabbi/plugin-scaffolder@vrabbi/plugin-scaffolder-react@yearn-finance/web-libappskd@arthurcerqueira/core-components@backstage/plugin-auth-react@backstage/plugin-gcp-projects@backstage/plugin-scaffolder@backstage/core-components@backstage-community/plugin-gcp-projects@backstage-community/plugin-entity-validation@backstage/plugin-scaffolder-react@backstage/plugin-techdocs-module-addons-contrib@backstage/plugin-catalog-react@backstage/plugin-entity-validation@cloudbase/weda-ui@chaibuilder/sdk@andythehood/plugin-apigee@andythehood/plugin-gcp-projectskedao@builtbymom/web3@apptrium/web-host@diamondlightsource/davidianftfast2reservoir-kit-uinfttestzreservoir-kit-uinfttestzreservoir-kit-ui-2nfttestzreservoir-kit-ui-3didit-sdkdiditsdktest@prezly/analytics-nextjs@prezly/content-renderer-react-js@prezly/theme-kit-ui@pzh-ui/components
24.0.4

3 months ago

24.0.3

3 months ago

24.0.2

5 months ago

24.0.1

5 months ago

24.0.0

5 months ago

23.1.0

10 months ago

23.0.1

12 months ago

23.0.0

1 year ago

19.0.0

1 year ago

21.0.0

1 year ago

16.1.0

2 years ago

17.0.1

2 years ago

17.0.0

2 years ago

19.2.0

1 year ago

22.0.0

1 year ago

18.0.1

1 year ago

18.0.0

1 year ago

20.0.1

1 year ago

20.0.0

1 year ago

20.0.3

1 year ago

20.0.2

1 year ago

19.1.0

1 year ago

20.1.0

1 year ago

16.0.1

2 years ago

16.0.0

2 years ago

14.5.0

2 years ago

14.5.1

2 years ago

15.0.0

2 years ago

15.0.1

2 years ago

14.2.3

2 years ago

14.6.0

2 years ago

15.1.0

2 years ago

14.3.0

2 years ago

14.7.0

2 years ago

14.7.1

2 years ago

14.4.0

2 years ago

14.1.0

2 years ago

14.0.0

2 years ago

14.2.0

2 years ago

14.2.1

2 years ago

14.2.2

2 years ago

13.3.0

2 years ago

13.2.0

2 years ago

13.2.1

2 years ago

13.1.0

2 years ago

12.2.0

2 years ago

13.0.0

2 years ago

12.3.0

2 years ago

12.1.2

2 years ago

12.1.0

2 years ago

12.1.1

2 years ago

12.0.3

2 years ago

12.0.4

2 years ago

12.0.0

3 years ago

11.0.0

3 years ago

11.1.0

3 years ago

10.0.0

3 years ago

10.1.0

3 years ago

10.1.1

3 years ago

8.0.0

3 years ago

9.0.0

3 years ago

6.1.0

3 years ago

7.0.0

3 years ago

6.0.1

3 years ago

6.0.0

3 years ago

5.0.0

3 years ago

4.0.0

3 years ago

3.8.0

3 years ago

3.6.0

3 years ago

3.7.0

3 years ago

3.4.0

3 years ago

3.5.0

3 years ago

3.2.0

3 years ago

3.3.0

3 years ago

2.2.0

3 years ago

3.0.1

3 years ago

3.0.0

3 years ago

3.1.0

3 years ago

2.0.0

3 years ago

2.1.0

3 years ago

1.28.0

3 years ago

1.25.0

3 years ago

1.25.1

3 years ago

1.27.0

3 years ago

1.24.1

3 years ago

1.26.0

3 years ago

1.24.0

3 years ago

1.15.0

3 years ago

1.14.0

3 years ago

1.13.0

3 years ago

1.12.0

3 years ago

1.19.0

3 years ago

1.18.0

3 years ago

1.17.0

3 years ago

1.16.0

3 years ago

1.9.1

3 years ago

1.7.3

3 years ago

1.9.0

3 years ago

1.7.2

3 years ago

1.8.0

3 years ago

1.7.1

3 years ago

1.6.2

3 years ago

1.7.0

3 years ago

1.6.1

3 years ago

1.4.3

3 years ago

1.6.0

3 years ago

1.5.0

3 years ago

1.21.0

3 years ago

1.20.1

3 years ago

1.22.0

3 years ago

1.20.2

3 years ago

1.20.0

3 years ago

1.23.0

3 years ago

1.20.3

3 years ago

1.20.4

3 years ago

1.7.5

3 years ago

1.7.4

3 years ago

1.11.0

3 years ago

1.10.0

3 years ago

1.4.2

3 years ago

1.4.1

3 years ago

1.2.3

3 years ago

1.4.0

3 years ago

1.3.0

3 years ago

1.2.2

3 years ago

1.2.1

3 years ago

1.2.0

3 years ago

1.1.0

3 years ago

1.0.0

3 years ago