|
1 |
| -# vue-next-use |
| 1 | +<div align="center"> |
| 2 | + <h1> |
| 3 | + <br/> |
| 4 | + <br/> |
| 5 | + 👍 |
| 6 | + <br /> |
| 7 | + vue-next-use |
| 8 | + <br /> |
| 9 | + <sup style="font-size: 16px; font-weight: 300;"> |
| 10 | + a vue3 <a href="https://github.com/streamich/react-use" target="_blank">react-use</a> implementation |
| 11 | + </sup> |
| 12 | + <br /> |
| 13 | + <br /> |
| 14 | + <br /> |
| 15 | + </h1> |
| 16 | + <sup> |
| 17 | + <br /> |
| 18 | + <br /> |
| 19 | + <a href="https://www.npmjs.com/package/vue-next-use"> |
| 20 | + <img src="https://img.shields.io/npm/v/vue-next-use.svg" alt="npm package" /> |
| 21 | + </a> |
| 22 | + <!-- |
| 23 | + <a href="https://www.npmjs.com/package/vue-next-use"> |
| 24 | + <img src="https://img.shields.io/npm/dm/vue-next-use.svg" alt="npm downloads" /> |
| 25 | + </a> |
| 26 | + --> |
| 27 | + <a href="http://niqingyang.github.io/vue-next-use"> |
| 28 | + <img src="https://img.shields.io/badge/demos-🚀-yellow.svg" alt="demos" /> |
| 29 | + </a> |
| 30 | + <br /> |
| 31 | + </sup> |
| 32 | + <br /> |
| 33 | + <br /> |
| 34 | + <br /> |
| 35 | + <br /> |
| 36 | + <pre>npm i <a href="https://www.npmjs.com/package/vue-next-use">vue-next-use</a></pre> |
| 37 | + <br /> |
| 38 | + <br /> |
| 39 | + <br /> |
| 40 | + <br /> |
| 41 | + <br /> |
| 42 | +</div> |
2 | 43 |
|
3 |
| -a vue3 [react-use](https://github.com/streamich/react-use) implementation - it is under active development, and the interface may change greatly |
| 44 | +- [**Sensors**](./docs/Sensors.md) |
| 45 | + - [`useBattery`](./docs/useBattery.md) — tracks device battery state. [![][img-demo]](https://niqingyang.github.io/vue-next-use/?path=/story/sensors-usebattery--demo) |
| 46 | + - [`useGeolocation`](./docs/useGeolocation.md) — tracks geo location state of user's device. [![][img-demo]](https://niqingyang.github.io/vue-next-use/?path=/story/sensors-usegeolocation--demo) |
| 47 | + - [`useHover` and `useHoverDirty`](./docs/useHover.md) — tracks mouse hover state of some element. [![][img-demo]](https://niqingyang.github.io/vue-next-use/?path=/story/sensors-usehover--demo) |
| 48 | + - [`useHash`](./docs/useHash.md) — tracks location hash value. [![][img-demo]](https://niqingyang.github.io/vue-next-use/?path=/story/sensors-usehash--demo) |
| 49 | + - [`useIdle`](./docs/useIdle.md) — tracks whether user is being inactive. |
| 50 | + - [`useIntersection`](./docs/useIntersection.md) — tracks an HTML element's intersection. [![][img-demo]](https://niqingyang.github.io/vue-next-use/?path=/story/sensors-useintersection--demo) |
| 51 | + - [`useKey`](./docs/useKey.md), [`useKeyPress`](./docs/useKeyPress.md), [`useKeyboardJs`](./docs/useKeyboardJs.md), and [`useKeyPressEvent`](./docs/useKeyPressEvent.md) — track keys. [![][img-demo]](https://niqingyang.github.io/vue-next-use/?path=/story/sensors-usekeypressevent--demo) |
| 52 | + - [`useLocation`](./docs/useLocation.md) and [`useSearchParam`](./docs/useSearchParam.md) — tracks page navigation bar location state. |
| 53 | + - [`useLongPress`](./docs/useLongPress.md) — tracks long press gesture of some element. |
| 54 | + - [`useMedia`](./docs/useMedia.md) — tracks state of a CSS media query. [![][img-demo]](https://niqingyang.github.io/vue-next-use/?path=/story/sensors-usemedia--demo) |
| 55 | + - [`useMediaDevices`](./docs/useMediaDevices.md) — tracks state of connected hardware devices. |
| 56 | + - [`useMotion`](./docs/useMotion.md) — tracks state of device's motion sensor. |
| 57 | + - [`useMouse` and `useMouseHovered`](./docs/useMouse.md) — tracks state of mouse position. [![][img-demo]](https://niqingyang.github.io/vue-next-use/?path=/story/sensors-usemouse--docs) |
| 58 | + - [`useMouseWheel`](./docs/useMouseWheel.md) — tracks deltaY of scrolled mouse wheel. [![][img-demo]](https://niqingyang.github.io/vue-next-use/?path=/story/sensors-usemousewheel--docs) |
| 59 | + - [`useNetworkState`](./docs/useNetworkState.md) — tracks the state of browser's network connection. [![][img-demo]](https://niqingyang.github.io/vue-next-use/?path=/story/sensors-usenetworkstate--demo) |
| 60 | + - [`useOrientation`](./docs/useOrientation.md) — tracks state of device's screen orientation. |
| 61 | + - [`usePageLeave`](./docs/usePageLeave.md) — triggers when mouse leaves page boundaries. |
| 62 | + - [`useScratch`](./docs/useScratch.md) — tracks mouse click-and-scrub state. |
| 63 | + - [`useScroll`](./docs/useScroll.md) — tracks an HTML element's scroll position. [![][img-demo]](https://niqingyang.github.io/vue-next-use/?path=/story/sensors-usescroll--docs) |
| 64 | + - [`useScrolling`](./docs/useScrolling.md) — tracks whether HTML element is scrolling. |
| 65 | + - [`useStartTyping`](./docs/useStartTyping.md) — detects when user starts typing. |
| 66 | + - [`useWindowScroll`](./docs/useWindowScroll.md) — tracks `Window` scroll position. [![][img-demo]](https://niqingyang.github.io/vue-next-use/?path=/story/sensors-usewindowscroll--docs) |
| 67 | + - [`useWindowSize`](./docs/useWindowSize.md) — tracks `Window` dimensions. [![][img-demo]](https://niqingyang.github.io/vue-next-use/?path=/story/sensors-usewindowsize--demo) |
| 68 | + - [`useMeasure`](./docs/useMeasure.md) and [`useSize`](./docs/useSize.md) — tracks an HTML element's dimensions. [![][img-demo]](https://niqingyang.github.io/vue-next-use/?path=/story/sensors-usemeasure--demo) |
| 69 | + - [`createBreakpoint`](./docs/createBreakpoint.md) — tracks `innerWidth` |
| 70 | + - [`useScrollbarWidth`](./docs/useScrollbarWidth.md) — detects browser's native scrollbars width. [![][img-demo]](https://niqingyang.github.io/vue-next-use/?path=/story/sensors-usescrollbarwidth--demo) |
| 71 | + <br/> |
| 72 | + <br/> |
| 73 | +- [**UI**](./docs/UI.md) |
| 74 | + - [`useAudio`](./docs/useAudio.md) — plays audio and exposes its controls. [![][img-demo]](https://niqingyang.github.io/vue-next-use/?path=/story/ui-useaudio--demo) |
| 75 | + - [`useClickAway`](./docs/useClickAway.md) — triggers callback when user clicks outside target area. |
| 76 | + - [`useCss`](./docs/useCss.md) — dynamically adjusts CSS. |
| 77 | + - [`useDrop` and `useDropArea`](./docs/useDrop.md) — tracks file, link and copy-paste drops. |
| 78 | + - [`useFullscreen`](./docs/useFullscreen.md) — display an element or video full-screen. [![][img-demo]](https://niqingyang.github.io/vue-next-use/?path=/story/ui-usefullscreen--demo) |
| 79 | + - [`useSlider`](./docs/useSlider.md) — provides slide behavior over any HTML element. [![][img-demo]](https://niqingyang.github.io/vue-next-use/?path=/story/ui-useslider--demo) |
| 80 | + - [`useSpeech`](./docs/useSpeech.md) — synthesizes speech from a text string. [![][img-demo]](https://niqingyang.github.io/vue-next-use/?path=/story/ui-usespeech--demo) |
| 81 | + - [`useVibrate`](./docs/useVibrate.md) — provide physical feedback using the [Vibration API](https://developer.mozilla.org/en-US/docs/Web/API/Vibration_API). [![][img-demo]](https://niqingyang.github.io/vue-next-use/?path=/story/ui-usevibrate--demo) |
| 82 | + - [`useVideo`](./docs/useVideo.md) — plays video, tracks its state, and exposes playback controls. [![][img-demo]](https://niqingyang.github.io/vue-next-use/?path=/story/ui-usevideo--demo) |
| 83 | + <br/> |
| 84 | + <br/> |
| 85 | +- [**Animations**](./docs/Animations.md) |
| 86 | + - [`useRaf`](./docs/useRaf.md) — re-renders component on each `requestAnimationFrame`. |
| 87 | + - [`useInterval`](./docs/useInterval.md) and [`useHarmonicIntervalFn`](./docs/useHarmonicIntervalFn.md) — re-renders component on a set interval using `setInterval`. |
| 88 | + - [`useSpring`](./docs/useSpring.md) — interpolates number over time according to spring dynamics. |
| 89 | + - [`useTimeout`](./docs/useTimeout.md) — re-renders component after a timeout. |
| 90 | + - [`useTimeoutFn`](./docs/useTimeoutFn.md) — calls given function after a timeout. [![][img-demo]](https://niqingyang.github.io/vue-next-use/?path=/story/animation-usetimeoutfn--demo) |
| 91 | + - [`useTween`](./docs/useTween.md) — re-renders component, while tweening a number from 0 to 1. [![][img-demo]](https://niqingyang.github.io/vue-next-use/?path=/story/animation-usetween--easing-demo) |
| 92 | + - [`useUpdate`](./docs/useUpdate.md) — returns a callback, which re-renders component when called. |
| 93 | + <br/> |
| 94 | + <br/> |
| 95 | +- [**Side-effects**](./docs/Side-effects.md) |
| 96 | + - [`useAsync`](./docs/useAsync.md), [`useAsyncFn`](./docs/useAsyncFn.md), and [`useAsyncRetry`](./docs/useAsyncRetry.md) — resolves an `async` function. |
| 97 | + - [`useBeforeUnload`](./docs/useBeforeUnload.md) — shows browser alert when user try to reload or close the page. |
| 98 | + - [`useCookie`](./docs/useCookie.md) — provides way to read, update and delete a cookie. [![][img-demo]](https://niqingyang.github.io/vue-next-use/?path=/story/side-effects-usecookie--demo) |
| 99 | + - [`useCopyToClipboard`](./docs/useCopyToClipboard.md) — copies text to clipboard. |
| 100 | + - [`useDebounce`](./docs/useDebounce.md) — debounces a function. [![][img-demo]](https://niqingyang.github.io/vue-next-use/?path=/story/side-effects-usedebounce--demo) |
| 101 | + - [`useError`](./docs/useError.md) — error dispatcher. [![][img-demo]](https://niqingyang.github.io/vue-next-use/?path=/story/side-effects-useerror--demo) |
| 102 | + - [`useFavicon`](./docs/useFavicon.md) — sets favicon of the page. |
| 103 | + - [`useLocalStorage`](./docs/useLocalStorage.md) — manages a value in `localStorage`. |
| 104 | + - [`useLockBodyScroll`](./docs/useLockBodyScroll.md) — lock scrolling of the body element. |
| 105 | + - [`useRafLoop`](./docs/useRafLoop.md) — calls given function inside the RAF loop. |
| 106 | + - [`useSessionStorage`](./docs/useSessionStorage.md) — manages a value in `sessionStorage`. |
| 107 | + - [`useThrottle` and `useThrottleFn`](./docs/useThrottle.md) — throttles a function. [![][img-demo]](https://niqingyang.github.io/vue-next-use/?path=/story/side-effects-usethrottle--demo) |
| 108 | + - [`useTitle`](./docs/useTitle.md) — sets title of the page. |
| 109 | + - [`usePermission`](./docs/usePermission.md) — query permission status for browser APIs. |
| 110 | + <br/> |
| 111 | + <br/> |
| 112 | +- [**Lifecycles**](./docs/Lifecycles.md) |
| 113 | + - [`useEffectOnce`](./docs/useEffectOnce.md) — a modified [`useEffect`](https://reactjs.org/docs/hooks-reference.html#useeffect) hook that only runs once. |
| 114 | + - [`useEvent`](./docs/useEvent.md) — subscribe to events. |
| 115 | + - [`useLifecycles`](./docs/useLifecycles.md) — calls `mount` and `unmount` callbacks. |
| 116 | + - [`useMountedState`](./docs/useMountedState.md) and [`useUnmountPromise`](./docs/useUnmountPromise.md) — track if component is mounted. |
| 117 | + - [`usePromise`](./docs/usePromise.md) — resolves promise only while component is mounted. |
| 118 | + - [`useLogger`](./docs/useLogger.md) — logs in console as component goes through life-cycles. |
| 119 | + - [`useMount`](./docs/useMount.md) — calls `mount` callbacks. |
| 120 | + - [`useUnmount`](./docs/useUnmount.md) — calls `unmount` callbacks. |
| 121 | + - [`useUpdateEffect`](./docs/useUpdateEffect.md) — run an `effect` only on updates. |
| 122 | + - [`useIsomorphicLayoutEffect`](./docs/useIsomorphicLayoutEffect.md) — `useLayoutEffect` that does not show warning when server-side rendering. |
| 123 | + - [`useDeepCompareEffect`](./docs/useDeepCompareEffect.md), [`useShallowCompareEffect`](./docs/useShallowCompareEffect.md), and [`useCustomCompareEffect`](./docs/useCustomCompareEffect.md) — run an `effect` depending on deep comparison of its dependencies |
| 124 | + <br/> |
| 125 | + <br/> |
| 126 | +- [**State**](./docs/State.md) |
| 127 | + - [`createMemo`](./docs/createMemo.md) — factory of memoized hooks. |
| 128 | + - [`createReducer`](./docs/createReducer.md) — factory of reducer hooks with custom middleware. |
| 129 | + - [`createReducerContext`](./docs/createReducerContext.md) and [`createStateContext`](./docs/createStateContext.md) — factory of hooks for a sharing state between components. |
| 130 | + - [`useDefault`](./docs/useDefault.md) — returns the default value when state is `null` or `undefined`. |
| 131 | + - [`useGetSet`](./docs/useGetSet.md) — returns state getter `get()` instead of raw state. |
| 132 | + - [`useGetSetState`](./docs/useGetSetState.md) — as if [`useGetSet`](./docs/useGetSet.md) and [`useSetState`](./docs/useSetState.md) had a baby. |
| 133 | + - [`useLatest`](./docs/useLatest.md) — returns the latest state or props |
| 134 | + - [`usePrevious`](./docs/usePrevious.md) — returns the previous state or props. [![][img-demo]](https://codesandbox.io/s/fervent-galileo-krgx6) |
| 135 | + - [`usePreviousDistinct`](./docs/usePreviousDistinct.md) — like `usePrevious` but with a predicate to determine if `previous` should update. |
| 136 | + - [`useObservable`](./docs/useObservable.md) — tracks latest value of an `Observable`. |
| 137 | + - [`useRafState`](./docs/useRafState.md) — creates `setState` method which only updates after `requestAnimationFrame`. [![][img-demo]](https://niqingyang.github.io/vue-next-use/?path=/story/state-userafstate--demo) |
| 138 | + - [`useSetState`](./docs/useSetState.md) — creates `setState` method which works like `this.setState`. [![][img-demo]](https://niqingyang.github.io/vue-next-use/?path=/story/state-usesetstate--demo) |
| 139 | + - [`useStateList`](./docs/useStateList.md) — circularly iterates over an array. [![][img-demo]](https://niqingyang.github.io/vue-next-use/?path=/story/state-usestatelist--demo) |
| 140 | + - [`useToggle` and `useBoolean`](./docs/useToggle.md) — tracks state of a boolean. [![][img-demo]](https://niqingyang.github.io/vue-next-use/?path=/story/state-usetoggle--demo) |
| 141 | + - [`useCounter` and `useNumber`](./docs/useCounter.md) — tracks state of a number. [![][img-demo]](https://niqingyang.github.io/vue-next-use/?path=/story/state-usecounter--demo) |
| 142 | + - [`useList`](./docs/useList.md) ~and [`useUpsert`](./docs/useUpsert.md)~ — tracks state of an array. [![][img-demo]](https://niqingyang.github.io/vue-next-use/?path=/story/state-uselist--demo) |
| 143 | + - [`useMap`](./docs/useMap.md) — tracks state of an object. [![][img-demo]](https://niqingyang.github.io/vue-next-use/?path=/story/state-usemap--demo) |
| 144 | + - [`useSet`](./docs/useSet.md) — tracks state of a Set. [![][img-demo]](https://codesandbox.io/s/bold-shtern-6jlgw) |
| 145 | + - [`useQueue`](./docs/useQueue.md) — implements simple queue. |
| 146 | + - [`useStateValidator`](./docs/useStateValidator.md) — tracks state of an object. [![][img-demo]](https://niqingyang.github.io/vue-next-use/?path=/story/state-usestatevalidator--demo) |
| 147 | + - [`useStateWithHistory`](./docs/useStateWithHistory.md) — stores previous state values and provides handles to travel through them. [![][img-demo]](https://niqingyang.github.io/vue-next-use/?path=/story/state-usestatewithhistory--demo) |
| 148 | + - [`useMultiStateValidator`](./docs/useMultiStateValidator.md) — alike the `useStateValidator`, but tracks multiple states at a time. [![][img-demo]](https://niqingyang.github.io/vue-next-use/?path=/story/state-usemultistatevalidator--demo) |
| 149 | + - [`useMediatedState`](./docs/useMediatedState.md) — like the regular `useState` but with mediation by custom function. [![][img-demo]](https://niqingyang.github.io/vue-next-use/?path=/story/state-usemediatedstate--demo) |
| 150 | + - [`useFirstMountState`](./docs/useFirstMountState.md) — check if current render is first. [![][img-demo]](https://niqingyang.github.io/vue-next-use/?path=/story/state-usefirstmountstate--demo) |
| 151 | + - [`useRendersCount`](./docs/useRendersCount.md) — count component renders. [![][img-demo]](https://niqingyang.github.io/vue-next-use/?path=/story/state-userenderscount--demo) |
| 152 | + - [`createGlobalState`](./docs/createGlobalState.md) — cross component shared state.[![][img-demo]](https://niqingyang.github.io/vue-next-use/?path=/story/state-createglobalstate--demo) |
| 153 | + - [`useMethods`](./docs/useMethods.md) — neat alternative to `useReducer`. [![][img-demo]](https://niqingyang.github.io/vue-next-use/?path=/story/state-usemethods--demo) |
| 154 | + <br/> |
| 155 | + <br/> |
| 156 | +- [**Miscellaneous**]() |
| 157 | + - [`useEnsuredForwardedRef`](./docs/useEnsuredForwardedRef.md) and [`ensuredForwardRef`](./docs/useEnsuredForwardedRef.md) — use a React.forwardedRef safely. [![][img-demo]](https://niqingyang.github.io/vue-next-use/?path=/story/state-useensuredforwardedref--demo) |
4 | 158 |
|
5 |
| -## Usage (beta) |
| 159 | +<br /> |
| 160 | +<br /> |
| 161 | +<br /> |
| 162 | +<br /> |
| 163 | +<br /> |
| 164 | +<br /> |
| 165 | +<br /> |
6 | 166 |
|
7 |
| -```bash |
8 |
| -npm install vue-next-use |
9 |
| -``` |
| 167 | +<p align="center"> |
| 168 | + <a href="./docs/Usage.md"><strong>Usage</strong></a> — how to import. |
| 169 | + <br /> |
| 170 | + <a href="./LICENSE"><strong>Unlicense</strong></a> — public domain. |
| 171 | + <br /> |
| 172 | + <a href="https://opencollective.com/vue-next-use/contribute"><strong>Support</strong></a> — add yourself to backer list below. |
| 173 | +</p> |
10 | 174 |
|
11 |
| -or |
| 175 | +<br /> |
| 176 | +<br /> |
| 177 | +<br /> |
| 178 | +<br /> |
| 179 | +<br /> |
12 | 180 |
|
13 |
| -```bash |
14 |
| -yarn add vue-next-use |
15 |
| -``` |
| 181 | +[img-demo]: https://img.shields.io/badge/demo-%20%20%20%F0%9F%9A%80-green.svg |
16 | 182 |
|
17 |
| -## Done |
| 183 | +<div align="center"> |
| 184 | + <h1>Contributors</h1> |
| 185 | +</div> |
18 | 186 |
|
19 |
| -- useAsync |
20 |
| -- useAsyncFn |
21 |
| -- useAsyncRetry |
22 |
| -- useBeforeUnload |
23 |
| -- useClickAway |
24 |
| -- useComputedSetState |
25 |
| -- useComputedState |
26 |
| -- useCookie |
27 |
| -- useCopyToClipboard |
28 |
| -- useDrop |
29 |
| -- useDropArea |
30 |
| -- useEffect |
31 |
| -- useEvent |
32 |
| -- useFullscreen |
33 |
| -- useGeolocation |
34 |
| -- useGetSet |
35 |
| -- useHarmonicIntervalFn |
36 |
| -- useHash |
37 |
| -- useHover |
38 |
| -- useHoverDirty |
39 |
| -- useIdle |
40 |
| -- useIntersection |
41 |
| -- useInterval |
42 |
| -- useKey |
43 |
| -- useKeyboardJs |
44 |
| -- useKeyPress |
45 |
| -- useKeyPressEvent |
46 |
| -- useList |
47 |
| -- useLocation |
48 |
| -- useLongPress |
49 |
| -- useMap |
50 |
| -- useMount |
51 |
| -- useMountedState |
52 |
| -- useQueue |
53 |
| -- useReactive |
54 |
| -- useReadonly |
55 |
| -- useSet |
56 |
| -- useSetState |
57 |
| -- useSlider |
58 |
| -- useSpeech |
59 |
| -- useSpring |
60 |
| -- useState |
61 |
| -- useTimeout |
62 |
| -- useTimeoutFn |
63 |
| -- useToggle |
64 |
| -- useVideo |
| 187 | +<br /> |
| 188 | +<br /> |
65 | 189 |
|
66 |
| -## Other |
| 190 | +<a href="https://github.com/streamich/vue-next-use/graphs/contributors"><img src="https://opencollective.com/vue-next-use/contributors.svg?width=890&button=false" /></a> |
| 191 | + |
| 192 | +<br /> |
| 193 | +<br /> |
| 194 | +<br /> |
| 195 | +<br /> |
| 196 | +<br /> |
67 | 197 |
|
68 |
| -doing... |
|
0 commit comments