React hooks done right, for browser and SSR.
Installations
npm install @react-hookz/web
Score
89.7
Supply Chain
94.1
Quality
81.7
Maintenance
100
Vulnerability
100
License
Developer
Developer Guide
Module System
ESM
Min. Node Version
>=18.0.0
Typescript Support
Yes
Node Version
20.9.0
NPM Version
10.2.5
Statistics
1,931 Stars
1,565 Commits
94 Forks
7 Watching
22 Branches
23 Contributors
Updated on 28 Nov 2024
Bundle Size
20.51 kB
Minified
6.14 kB
Minified + Gzipped
Languages
TypeScript (80.47%)
MDX (18.54%)
JavaScript (0.95%)
Shell (0.04%)
Total Downloads
Cumulative downloads
Total Downloads
17,287,375
Last day
-10.3%
29,954
Compared to previous day
Last week
-1.5%
173,264
Compared to previous week
Last month
3.1%
737,339
Compared to previous month
Last year
35.8%
8,602,467
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
Dependencies
1
Dev Dependencies
37
@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:
1npm i @react-hookz/web 2# or 3yarn 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:
1// from the root of package 2import { useMountEffect } from '@react-hookz/web'; 3// or single hook directly 4import { 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
useDebouncedCallback
— Makes passed function debounced, otherwise acts likeuseCallback
.useRafCallback
— Makes passed function to be called within next animation frame.useThrottledCallback
— Makes passed function throttled, otherwise acts likeuseCallback
.
-
Lifecycle
useConditionalEffect
— LikeuseEffect
but callback invoked only if given conditions match a given predicate.useCustomCompareEffect
— LikeuseEffect
but uses a provided comparator function to validate dependency changes.useDebouncedEffect
— LikeuseEffect
, but passed function is debounced.useDeepCompareEffect
— LikeuseEffect
but uses@react-hookz/deep-equal
comparator function to validate deep dependency changes.useFirstMountState
— Returns a boolean that istrue
only on first render.useIntervalEffect
— LikesetInterval
but in the form of a React hook.useIsMounted
— Returns a function that yields current mount state.useIsomorphicLayoutEffect
— LikeuseLayoutEffect
but falls back touseEffect
during SSR.useMountEffect
— Run an effect only when a component mounts.useRafEffect
— LikeuseEffect
, but the effect is only run within an animation frame.useRerender
— Returns a callback that re-renders the component.useThrottledEffect
— LikeuseEffect
, but the passed function is throttled.useTimeoutEffect
— LikesetTimeout
, but in the form of a React hook.useUnmountEffect
— Run an effect only when a component unmounts.useUpdateEffect
— An effect hook that ignores the first render (not invoked on mount).useLifecycleLogger
— This hook provides logging when the component mounts, updates and unmounts.
-
State
useControlledRerenderState
— LikeuseState
, but its state setter accepts an extra argument, that allows cancelling renders.useCounter
— Tracks a numeric value and offers functions for manipulating it.useDebouncedState
— LikeuseState
but its state setter is debounced.useFunctionalState
— LikeuseState
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 aMap
.useMediatedState
— LikeuseState
, 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
— LikeReact.useState
, but state is only updated within animation frame.useRenderCount
— Tracks component's render count including first render.useSet
— Tracks the state of aSet
.useToggle
— LikeuseState
, but can only betrue
orfalse
.useThrottledState
— LikeuseState
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
— LikeuseRef
, but it returns an immutable ref that contains the actual value.useCustomCompareMemo
— LikeuseMemo
but uses provided comparator function to validate dependency changes.useDeepCompareMemo
— LikeuseMemo
but uses@react-hookz/deep-equal
comparator function to validate deep dependency changes.useHookableRef
— LikeuseRef
but it is possible to define handlers for getting and setting the value.
-
Side-effect
useAsync
— Executes provided async function and tracks its results and errors.useAsyncAbortable
— LikeuseAsync
, but also providesAbortSignal
as first function argument to the async function.useCookieValue
— Manages a single cookie.useLocalStorageValue
— Manages a single LocalStorage key.useSessionStorageValue
— Manages a single SessionStorage key.
-
Sensor
useIntersectionObserver
— Observe changes in the intersection of a target element with an ancestor element or with the viewport.useMeasure
— UsesResizeObserver
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 wheneverResizeObserver
detects a change to the target's size.useScreenOrientation
— Checks if the screen is inportrait
orlandscape
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
No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
license file detected
Details
- Info: project has a license file: LICENSE:0
- Info: FSF or OSI recognized license: MIT License: LICENSE:0
Reason
3 existing vulnerabilities detected
Details
- Warn: Project is vulnerable to: GHSA-grv7-fg5c-xmjg
- Warn: Project is vulnerable to: GHSA-3xgq-45jj-v275
- Warn: Project is vulnerable to: GHSA-952p-6rrq-rcjv
Reason
8 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 6
Reason
badge detected: InProgress
Reason
Found 0/12 approved changesets -- score normalized to 0
Reason
detected GitHub workflow tokens with excessive permissions
Details
- Warn: jobLevel 'contents' permission set to 'write': .github/workflows/ci-cd.yml:94
- Warn: jobLevel 'contents' permission set to 'write': .github/workflows/ci-cd.yml:141
- Warn: no topLevel permission defined: .github/workflows/ci-cd.yml:1
- Warn: no topLevel permission defined: .github/workflows/discord-release-notify.yml:1
Reason
security policy file not detected
Details
- Warn: no security policy file detected
- Warn: no security file to analyze
- Warn: no security file to analyze
- Warn: no security file to analyze
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/ci-cd.yml:21: update your workflow using https://app.stepsecurity.io/secureworkflow/react-hookz/web/ci-cd.yml/master?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/ci-cd.yml:25: update your workflow using https://app.stepsecurity.io/secureworkflow/react-hookz/web/ci-cd.yml/master?enable=pin
- Warn: third-party GitHubAction not pinned by hash: .github/workflows/ci-cd.yml:29: update your workflow using https://app.stepsecurity.io/secureworkflow/react-hookz/web/ci-cd.yml/master?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/ci-cd.yml:42: update your workflow using https://app.stepsecurity.io/secureworkflow/react-hookz/web/ci-cd.yml/master?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/ci-cd.yml:46: update your workflow using https://app.stepsecurity.io/secureworkflow/react-hookz/web/ci-cd.yml/master?enable=pin
- Warn: third-party GitHubAction not pinned by hash: .github/workflows/ci-cd.yml:50: update your workflow using https://app.stepsecurity.io/secureworkflow/react-hookz/web/ci-cd.yml/master?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/ci-cd.yml:66: update your workflow using https://app.stepsecurity.io/secureworkflow/react-hookz/web/ci-cd.yml/master?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/ci-cd.yml:70: update your workflow using https://app.stepsecurity.io/secureworkflow/react-hookz/web/ci-cd.yml/master?enable=pin
- Warn: third-party GitHubAction not pinned by hash: .github/workflows/ci-cd.yml:74: update your workflow using https://app.stepsecurity.io/secureworkflow/react-hookz/web/ci-cd.yml/master?enable=pin
- Warn: third-party GitHubAction not pinned by hash: .github/workflows/ci-cd.yml:83: update your workflow using https://app.stepsecurity.io/secureworkflow/react-hookz/web/ci-cd.yml/master?enable=pin
- Warn: third-party GitHubAction not pinned by hash: .github/workflows/ci-cd.yml:98: update your workflow using https://app.stepsecurity.io/secureworkflow/react-hookz/web/ci-cd.yml/master?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/ci-cd.yml:112: update your workflow using https://app.stepsecurity.io/secureworkflow/react-hookz/web/ci-cd.yml/master?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/ci-cd.yml:116: update your workflow using https://app.stepsecurity.io/secureworkflow/react-hookz/web/ci-cd.yml/master?enable=pin
- Warn: third-party GitHubAction not pinned by hash: .github/workflows/ci-cd.yml:120: update your workflow using https://app.stepsecurity.io/secureworkflow/react-hookz/web/ci-cd.yml/master?enable=pin
- Warn: third-party GitHubAction not pinned by hash: .github/workflows/ci-cd.yml:130: update your workflow using https://app.stepsecurity.io/secureworkflow/react-hookz/web/ci-cd.yml/master?enable=pin
- Warn: third-party GitHubAction not pinned by hash: .github/workflows/ci-cd.yml:144: update your workflow using https://app.stepsecurity.io/secureworkflow/react-hookz/web/ci-cd.yml/master?enable=pin
- Warn: third-party GitHubAction not pinned by hash: .github/workflows/discord-release-notify.yml:15: update your workflow using https://app.stepsecurity.io/secureworkflow/react-hookz/web/discord-release-notify.yml/master?enable=pin
- Info: 0 out of 8 GitHub-owned GitHubAction dependencies pinned
- Info: 0 out of 9 third-party GitHubAction dependencies pinned
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
branch protection not enabled on development/release branches
Details
- Warn: branch protection not enabled for branch 'master'
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
- Warn: 0 commits out of 23 are checked with a SAST tool
Score
3.8
/10
Last Scanned on 2024-11-18
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn MoreOther packages similar to @react-hookz/web
@react-hookz/deep-equal
Fast deep equal comparator
react-square-web-payments-sdk
`react-square-web-payments-sdk` lets you easily create PCI-compliant inputs to accept payments online with the Square Payments API. It supports the following payment methods: credit and debit cards, ACH bank transfers, Apple Pay, Google Pay, and Gift Card
@react-spring/web
`react-dom` support
react-native-web
React Native for Web