web

所属分类:Python编程
开发工具:TypeScript
文件大小:0KB
下载次数:0
上传日期:2023-06-28 01:01:03
上 传 者sh-1993
说明:  对浏览器和SSR执行正确的 React挂钩。
(React hooks done right, for browser and SSR.)

文件列表:
.editorconfig (210, 2023-12-24)
.eslintignore (87, 2023-12-24)
.eslintrc.cjs (1061, 2023-12-24)
.husky/ (0, 2023-12-24)
.husky/commit-msg (147, 2023-12-24)
.husky/pre-commit (59, 2023-12-24)
.npmignore (32, 2023-12-24)
.prettierrc.cjs (96, 2023-12-24)
CHANGELOG.md (49831, 2023-12-24)
CONTRIBUTING.md (5566, 2023-12-24)
LICENSE (1068, 2023-12-24)
commitlint.config.cjs (131, 2023-12-24)
jest.config.ts (928, 2023-12-24)
package.json (2904, 2023-12-24)
src/ (0, 2023-12-24)
src/__docs__/ (0, 2023-12-24)
src/__docs__/Introduction.story.mdx (2862, 2023-12-24)
src/__docs__/migrating-from-react-use.story.mdx (17459, 2023-12-24)
src/__tests__/ (0, 2023-12-24)
src/__tests__/navigator.vibrate.ts (111, 2023-12-24)
src/__tests__/setup.ts (193, 2023-12-24)
src/index.ts (2872, 2023-12-24)
... ...

# ![@react-hookz/web](https://github.com/react-hookz/web/blob/master/.github/logo.png) [![NPM Version](https://github.com/react-hookz/web/blob/master/https://flat.badgen.net/npm/v/@react-hookz/web)](https://github.com/react-hookz/web/blob/master/https://www.npmjs.com/package/@react-hookz/web) [![NPM Downloads](https://github.com/react-hookz/web/blob/master/https://flat.badgen.net/npm/dm/@react-hookz/web)](https://github.com/react-hookz/web/blob/master/https://www.npmjs.com/package/@react-hookz/web) [![NPM Dependents](https://github.com/react-hookz/web/blob/master/https://flat.badgen.net/npm/dependents/@react-hookz/web)](https://github.com/react-hookz/web/blob/master/https://www.npmjs.com/package/@react-hookz/web) [![Build](https://github.com/react-hookz/web/blob/master/https://img.shields.io/github/actions/workflow/status/react-hookz/web/ci-cd.yml?branch=master&style=flat-square)](https://github.com/react-hookz/web/blob/master/https://github.com/react-hookz/web/actions) [![Coverage](https://github.com/react-hookz/web/blob/master/https://flat.badgen.net/codecov/c/github/react-hookz/web)](https://github.com/react-hookz/web/blob/master/https://app.codecov.io/gh/react-hookz/web) [![Types](https://github.com/react-hookz/web/blob/master/https://flat.badgen.net/npm/types/@react-hookz/web)](https://github.com/react-hookz/web/blob/master/https://www.npmjs.com/package/@react-hookz/web) [![Tree Shaking](https://github.com/react-hookz/web/blob/master/https://flat.badgen.net/bundlephobia/tree-shaking/@react-hookz/web)](https://github.com/react-hookz/web/blob/master/https://bundlephobia.com/result?p=@react-hookz/web) × **[DOCS](https://github.com/react-hookz/web/blob/master/https://react-hookz.github.io/web/)** × **[DISCORD](https://github.com/react-hookz/web/blob/master/https://discord.gg/Fjwphtu65f)** × **[CHANGELOG](https://github.com/react-hookz/web/blob/master/https://github.com/react-hookz/web/blob/master/CHANGELOG.md)** ×
--- `@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: ```shell 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 both, CJS and ES imports. > 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: ```ts // from the root of package import { useMountEffect } from '@react-hookz/web'; // or single hook directly import { useMountEffect } from '@react-hookz/web/esm/useMountEffect'; ``` 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. In case, for some reason, you are not able to use ES imports - you should direct-import hooks from `@react-hookz/web/esm` folder. ## Migrating from react-use `@react-hookz/web` was built as a [spiritual successor](https://github.com/react-hookz/web/blob/master/https://github.com/streamich/react-use/issues/1974) of `react-use` by one of its former maintainers. Coming from `react-use`? Check out our [migration guide](https://github.com/react-hookz/web/blob/master/https://react-hookz.github.io/web/?path=/docs/migrating-from-react-use--page). ## Hooks list - #### Callback - [**`useDebouncedCallback`**](https://github.com/react-hookz/web/blob/master/https://react-hookz.github.io/web/?path=/docs/callback-usedebouncedcallback--example) — Makes passed function debounced, otherwise acts like `useCallback`. - [**`useRafCallback`**](https://github.com/react-hookz/web/blob/master/https://react-hookz.github.io/web/?path=/docs/callback-userafcallback--example) — Makes passed function to be called within next animation frame. - [**`useThrottledCallback`**](https://github.com/react-hookz/web/blob/master/https://react-hookz.github.io/web/?path=/docs/callback-usethrottledcallback--example) — Makes passed function throttled, otherwise acts like `useCallback`. - #### Lifecycle - [**`useConditionalEffect`**](https://github.com/react-hookz/web/blob/master/https://react-hookz.github.io/web/?path=/docs/lifecycle-useconditionaleffect--example) — Like `useEffect` but callback invoked only if given conditions match a given predicate. - [**`useCustomCompareEffect`**](https://github.com/react-hookz/web/blob/master/https://react-hookz.github.io/web/?path=/docs/lifecycle-usecustomcompareeffect--example) — Like `useEffect` but uses a provided comparator function to validate dependency changes. - [**`useDebouncedEffect`**](https://github.com/react-hookz/web/blob/master/https://react-hookz.github.io/web/?path=/docs/lifecycle-usedebouncedeffect--example) — Like `useEffect`, but passed function is debounced. - [**`useDeepCompareEffect`**](https://github.com/react-hookz/web/blob/master/https://react-hookz.github.io/web/?path=/docs/lifecycle-usedeepcompareeffect--example) — Like `useEffect` but uses `@react-hookz/deep-equal` comparator function to validate deep dependency changes. - [**`useFirstMountState`**](https://github.com/react-hookz/web/blob/master/https://react-hookz.github.io/web/?path=/docs/lifecycle-usefirstmountstate--example) — Returns a boolean that is `true` only on first render. - [**`useIntervalEffect`**](https://github.com/react-hookz/web/blob/master/https://react-hookz.github.io/web/?path=/docs/lifecycle-useintervaleffect--example) — Like `setInterval` but in the form of a React hook. - [**`useIsMounted`**](https://github.com/react-hookz/web/blob/master/https://react-hookz.github.io/web/?path=/docs/lifecycle-useismounted--example) — Returns a function that yields current mount state. - [**`useIsomorphicLayoutEffect`**](https://github.com/react-hookz/web/blob/master/https://react-hookz.github.io/web/?path=/docs/lifecycle-useisomorphiclayouteffect--page) — Like `useLayoutEffect` but falls back to `useEffect` during SSR. - [**`useMountEffect`**](https://github.com/react-hookz/web/blob/master/https://react-hookz.github.io/web/?path=/docs/lifecycle-usemounteffect--example) — Run an effect only when a component mounts. - [**`useRafEffect`**](https://github.com/react-hookz/web/blob/master/https://react-hookz.github.io/web/?path=/docs/lifecycle-useRafEffect--example) — Like `useEffect`, but the effect is only run within an animation frame. - [**`useRerender`**](https://github.com/react-hookz/web/blob/master/https://react-hookz.github.io/web/?path=/docs/lifecycle-usererender--example) — Returns a callback that re-renders the component. - [**`useThrottledEffect`**](https://github.com/react-hookz/web/blob/master/https://react-hookz.github.io/web/?path=/docs/lifecycle-usethrottledeffect--example) — Like `useEffect`, but the passed function is throttled. - [**`useTimeoutEffect`**](https://github.com/react-hookz/web/blob/master/https://react-hookz.github.io/web/?path=/docs/lifecycle-usetimeouteffect--example) — Like `setTimeout`, but in the form of a React hook. - [**`useUnmountEffect`**](https://github.com/react-hookz/web/blob/master/https://react-hookz.github.io/web/?path=/docs/lifecycle-useunmounteffect--example) — Run an effect only when a component unmounts. - [**`useUpdateEffect`**](https://github.com/react-hookz/web/blob/master/https://react-hookz.github.io/web/?path=/docs/lifecycle-useupdateeffect--example) — An effect hook that ignores the first render (not invoked on mount). - [**`useLifecycleLogger`**](https://github.com/react-hookz/web/blob/master/https://react-hookz.github.io/web/?path=/docs/lifecycle-uselifecycleLogger--example) — This hook provides logging when the component mounts, updates and unmounts. - #### State - [**`useControlledRerenderState`**](https://github.com/react-hookz/web/blob/master/https://react-hookz.github.io/web/?path=/docs/state-usecontrolledrerenderstate--example) — Like `useState`, but its state setter accepts an extra argument, that allows cancelling renders. - [**`useCounter`**](https://github.com/react-hookz/web/blob/master/https://react-hookz.github.io/web/?path=/docs/state-usecounter--example) — Tracks a numeric value and offers functions for manipulating it. - [**`useDebouncedState`**](https://github.com/react-hookz/web/blob/master/https://react-hookz.github.io/web/?path=/docs/state-usedebouncedstate--example) — Like `useState` but its state setter is debounced. - [**`useFunctionalState`**](https://github.com/react-hookz/web/blob/master/https://react-hookz.github.io/web/?path=/docs/state-usefunctionalstate--page) — Like `useState` but instead of raw state, a state getter function is returned. - [**`useList`**](https://github.com/react-hookz/web/blob/master/https://react-hookz.github.io/web/?path=/docs/state-uselist--example) — Tracks a list and offers functions for manipulating it. - [**`useMap`**](https://github.com/react-hookz/web/blob/master/https://react-hookz.github.io/web/?path=/docs/state-usemap--example) — Tracks the state of a `Map`. - [**`useMediatedState`**](https://github.com/react-hookz/web/blob/master/https://react-hookz.github.io/web/?path=/docs/state-usemediatedstate--example) — Like `useState`, but every value set is passed through a mediator function. - [**`usePrevious`**](https://github.com/react-hookz/web/blob/master/https://react-hookz.github.io/web/?path=/docs/state-useprevious--example) — Returns the value passed to the hook on previous render. - [**`usePreviousDistinct`**](https://github.com/react-hookz/web/blob/master/https://react-hookz.github.io/web/?path=/docs/state-usepreviousdistinct--example) — Returns the most recent distinct value passed to the hook on previous renders. - [**`useQueue`**](https://github.com/react-hookz/web/blob/master/https://react-hookz.github.io/web/?path=/docs/state-usequeue--example) — A state hook implementing FIFO queue. - [**`useRafState`**](https://github.com/react-hookz/web/blob/master/https://react-hookz.github.io/web/?path=/docs/state-userafstate--example) — Like `React.useState`, but state is only updated within animation frame. - [**`useRenderCount`**](https://github.com/react-hookz/web/blob/master/https://react-hookz.github.io/web/?path=/docs/state-userendercount--example) — Tracks component's render count including first render. - [**`useSet`**](https://github.com/react-hookz/web/blob/master/https://react-hookz.github.io/web/?path=/docs/state-useset--example) — Tracks the state of a `Set`. - [**`useToggle`**](https://github.com/react-hookz/web/blob/master/https://react-hookz.github.io/web/?path=/docs/state-usetoggle--example) — Like `useState`, but can only be `true` or `false`. - [**`useThrottledState`**](https://github.com/react-hookz/web/blob/master/https://react-hookz.github.io/web/?path=/docs/state-usethrottledstate--example) — Like `useState` but its state setter is throttled. - [**`useValidator`**](https://github.com/react-hookz/web/blob/master/https://react-hookz.github.io/web/?path=/docs/state-usevalidator--example) — Performs validation when any of the provided dependencies change. - #### Navigator - [**`useNetworkState`**](https://github.com/react-hookz/web/blob/master/https://react-hookz.github.io/web/?path=/docs/navigator-usenetworkstate--example) — Tracks the state of the browser's network connection. - [**`useVibrate`**](https://github.com/react-hookz/web/blob/master/https://react-hookz.github.io/web/?path=/docs/navigator-usevibrate--example) — Provides vibration feedback using the Vibration API. - [**`usePermission`**](https://github.com/react-hookz/web/blob/master/https://react-hookz.github.io/web/?path=/docs/navigator-usepermission--example) — Tracks the state of a permission. - #### Miscellaneous - [**`useSyncedRef`**](https://github.com/react-hookz/web/blob/master/https://react-hookz.github.io/web/?path=/docs/miscellaneous-usesyncedref--example) — Like `useRef`, but it returns an immutable ref that contains the actual value. - [**`useCustomCompareMemo`**](https://github.com/react-hookz/web/blob/master/https://react-hookz.github.io/web/?path=/docs/miscellaneous-useCustomCompareMemo--example) — Like `useMemo` but uses provided comparator function to validate dependency changes. - [**`useDeepCompareMemo`**](https://github.com/react-hookz/web/blob/master/https://react-hookz.github.io/web/?path=/docs/miscellaneous-useDeepCompareMemo--example) — Like `useMemo` but uses `@react-hookz/deep-equal` comparator function to validate deep dependency changes. - [**`useHookableRef`**](https://github.com/react-hookz/web/blob/master/https://react-hookz.github.io/web/?path=/docs/miscellaneous-usehookableref--example) — Like `useRef` but it is possible to define handlers for getting and setting the value. - #### Side-effect - [**`useAsync`**](https://github.com/react-hookz/web/blob/master/https://react-hookz.github.io/web/?path=/docs/side-effect-useasync--example) — Executes provided async function and tracks its results and errors. - [**`useAsyncAbortable`**](https://github.com/react-hookz/web/blob/master/https://react-hookz.github.io/web/?path=/docs/side-effect-useasyncabortable--example) — Like `useAsync`, but also provides `AbortSignal` as first function argument to the async function. - [**`useCookieValue`**](https://github.com/react-hookz/web/blob/master/https://react-hookz.github.io/web/?path=/docs/side-effect-usecookievalue--example) — Manages a single cookie. - [**`useLocalStorageValue`**](https://github.com/react-hookz/web/blob/master/https://react-hookz.github.io/web/?path=/docs/side-effect-uselocalstoragevalue--example) — Manages a single LocalStorage key. - [**`useSessionStorageValue`**](https://github.com/react-hookz/web/blob/master/https://react-hookz.github.io/web/?path=/docs/side-effect-usesessionstoragevalue--example) — Manages a single SessionStorage key. - #### Sensor - [**`useIntersectionObserver`**](https://github.com/react-hookz/web/blob/master/https://react-hookz.github.io/web/?path=/docs/sensor-useintersectionobserver--example) — Observe changes in the intersection of a target element with an ancestor element or with the viewport. - [**`useMeasure`**](https://github.com/react-hookz/web/blob/master/https://react-hookz.github.io/web/?path=/docs/sensor-usemeasure--example) — Uses `ResizeObserver` to track an element's dimensions and to re-render the component when they change. - [**`useMediaQuery`**](https://github.com/react-hookz/web/blob/master/https://react-hookz.github.io/web/?path=/docs/sensor-usemediaquery--example) — Tracks the state of a CSS media query. - [**`useResizeObserver`**](https://github.com/react-hookz/web/blob/master/https://react-hookz.github.io/web/?path=/docs/sensor-useresizeobserver--example) — Invokes a callback whenever `ResizeObserver` detects a change to the target's size. - [**`useScreenOrientation`**](https://github.com/react-hookz/web/blob/master/https://react-hookz.github.io/web/?path=/docs/sensor-usescreenorientation--example) — Checks if the screen is in `portrait` or `landscape` orientation and automatically re-renders on orientation change. - [**`useDocumentVisibility`**](https://github.com/react-hookz/web/blob/master/https://react-hookz.github.io/web/?path=/docs/sensor-usedocumentvisibility--example) — Tracks document visibility state. - #### Dom - [**`useClickOutside`**](https://github.com/react-hookz/web/blob/master/https://react-hookz.github.io/web/?path=/docs/dom-useclickoutside--example) — Triggers a callback when the user clicks outside a target element. - [**`useEventListener`**](https://github.com/react-hookz/web/blob/master/https://react-hookz.github.io/web/?path=/docs/dom-useeventlistener--example) — Subscribes an event listener to a target element. - [**`useKeyboardEvent`**](https://github.com/react-hookz/web/blob/master/https://react-hookz.github.io/web/?path=/docs/dom-usekeyboardevent--example) — Invokes a callback when a keyboard event occurs on the chosen target. - [**`useWindowSize`**](https://github.com/react-hookz/web/blob/master/https://react-hookz.github.io/web/?path=/docs/dom-usewindowsize--example) — Tracks the inner dimensions of the browser window. ## Contributors
xobotyi
Anton Zinovyev
JoeDuncko
Joe Duncko
ArttuOll
Arttu Olli
kylemh
Kyle Holmberg
AndreasNel
Andreas Nel
Rey-Wang
Rey Wang
wesgro
Jake Ketcheson
akd-io
Anders Kjr Damgaard
axelboc
Axel Bocciarelli
lensbart
Bart Lens
birant
Birant yigün
punkle
Brian Fletcher
ChloeMouret
Null
dantman
Daniel Friesen
JoshuaStewartEntelect
Joshua Stewart
jpwallace22
Justin Wallace
KonradLinkowski
Konrad Linkowski
MichalTarasiuk
Micha Tarasiuk
Myzel394
Null
paul-sachs
Paul Sachs
fengkx
Fengkx

近期下载者

相关文件


收藏者