-
Notifications
You must be signed in to change notification settings - Fork 102
Open
Labels
good first issueGood for newcomersGood for newcomers✨ enhancementNew feature or requestNew feature or request🆘 help wantedExtra attention is neededExtra attention is needed🎂 new hookNew hook addedNew hook added
Description
Our goal with @react-hookz/web
is to give the react community a general-purpose React hooks library built with care.
We'd like to port the remaining hooks from react-use (the project @react-hookz/web
grew out of) while keeping in mind our tenants:
- General-purposeness (hooks should fulfill a wide array of use cases)
- Composability (a preference for hooks that are useful for building other hooks)
- No or very few dependencies
- SSR compatibility
- 100% test coverage (ideally)
- Concrete example use cases
Hooks to port
Sensors
- useBattery — tracks device battery state.
- useGeolocation — tracks geo location state of user's device.
- useHover — tracks mouse hover state of some element.
- useHoverDirty — tracks mouse hover state of some element.
-
useHash — tracks location hash value.(No plans to implement. Instead, use one the various routing libraries available.) - useIdle — tracks whether user is being inactive.
- useIntersection — tracks an HTML element's intersection. (Implemented as useIntersectionObserver)
-
useKey — track keys.(Implemented as useKeyboardEvent) -
useKeyPress — track keys.(Implemented as useKeyboardEvent) -
useKeyboardJs — track keys.(Implemented as useKeyboardEvent) -
useKeyPressEvent — track keys.(Implemented as useKeyboardEvent) -
useLocation — tracks page navigation bar location state.(No plans to implement. Instead, use one the various routing libraries available.) -
useSearchParam — tracks page navigation bar location state.(No plans to implement. Instead, use one the various routing libraries available.) - useLongPress — tracks long press gesture of some element.
- useMedia — tracks state of a CSS media query. (implemented as useMediaQuery)
- useMediaDevices — tracks state of connected hardware devices.
- useMotion — tracks state of device's motion sensor.
- useMouse — tracks state of mouse position.
- useMouseHovered — tracks state of mouse position.
- useMouseWheel — tracks deltaY of scrolled mouse wheel.
- useNetworkState — tracks the state of browser's network connection. (implemented as useNetwork)
- useOrientation — tracks state of device's screen orientation.
- usePageLeave — triggers when mouse leaves page boundaries.
- useScratch — tracks mouse click-and-scrub state.
- useScroll — tracks an HTML element's scroll position.
- useScrolling — tracks whether HTML element is scrolling.
- useStartTyping — detects when user starts typing.
- useWindowScroll — tracks Window scroll position.
- useWindowSize — tracks Window dimensions.
- useMeasure — tracks an HTML element's dimensions. (implemented as useMeasure)
-
useSize — tracks an HTML element's dimensions.(UseuseWindowSize
instead) -
createBreakpoint — tracks innerWidth(Not planning to implement) - useScrollbarWidth — detects browser's native scrollbars width.
UI
- useAudio — plays audio and exposes its controls.
- useClickAway — triggers callback when user clicks outside target area. (Implmented as useClickOutside)
- useCss — dynamically adjusts CSS.
- useDrop — tracks file, link and copy-paste drops.
- useDropArea — tracks file, link and copy-paste drops.
- useFullscreen — display an element or video full-screen.
- useSlider — provides slide behavior over any HTML element.
- useSpeech — synthesizes speech from a text string.
- useVibrate — provide physical feedback using the Vibration API.
- useVideo — plays video, tracks its state, and exposes playback controls.
Animations
- useRaf — re-renders component on each requestAnimationFrame.
-
useInterval and useHarmonicIntervalFn — re-renders component on a set interval using setInterval.(Implemented asuseIntervalEffect
). - useSpring — interpolates number over time according to spring dynamics.
-
useTimeout — re-renders component after a timeout.(Can be composed from other hooks, see migration guide). -
useTimeoutFn — calls given function after a timeout.(Implemented asuseTimeoutEffect
). - useTween — re-renders component, while tweening a number from 0 to 1.
- useUpdate — returns a callback, which re-renders component when called. (Implemented as useRerender)
Side-effects
- useAsync — resolves an async function. (implemented as useAsync)
- useAsyncFn — resolves an async function. (implemented as useAsync)
- useAsyncRetry — resolves an async function. (implemented as useAsync)
-
useBeforeUnload — shows browser alert when user try to reload or close the page.(No plans to implement, address migration guide for workaround) - useCookie — provides way to read, update and delete a cookie. (implemented as useCookieValue)
-
useCopyToClipboard — copies text to clipboard.(no plans to implement - use browser's API instead) - useDebounce — debounces a function. (Implemented as useDebounceCallback)
- useError — error dispatcher.
-
useFavicon — sets favicon of the page.(Hooks that modify the element will not be implemented). - useLocalStorage — manages a value in localStorage. (Implemented as useLocalStorageValue)
- useLockBodyScroll — lock scrolling of the body element.
- useRafLoop — calls given function inside the RAF loop.
- useSessionStorage — manages a value in sessionStorage. (Implemented as useSessionStorageValue)
- useThrottle — throttles a function.
-
useThrottleFn — throttles a function. -
useTitle — sets title of the page.(Hooks that modify the element will not be implemented). - usePermission — query permission status for browser APIs. (Implemented as usePermission)
Lifecycles
-
useEffectOnce — a modified useEffect hook that only runs once.(it's just an alias foruseMountEffect
) - useEvent — subscribe to events. (Implemented as useEventListener)
-
useLifecycles — calls mount and unmount callbacks.(no sense to port, has almost no benefit comparing touseEffect
) - useMountedState — track if component is mounted. (Implemented as useIsMounted)
-
useUnmountPromise — track if component is mounted.(No plans to implement). -
usePromise — resolves promise only while component is mounted.(No plans to implement) -
useLogger — logs in console as component goes through life-cycles.(Implemented as useLifecycleLogger - useMount — calls mount callbacks. (Implemented as useMountEffect)
- useUnmount — calls unmount callbacks. (Implemented as useUnmountEffect)
- useUpdateEffect — run an effect only on updates. (Implemented as useUpdateEffect)
- useIsomorphicLayoutEffect — useLayoutEffect that does not show warning when server-side rendering. (Implemented as useIsomorphicLayoutEffect)
- useDeepCompareEffect — run an effect depending on deep comparison of its dependencies. (Implemented as useDeepCompareEffect)
- useShallowCompareEffect — run an effect depending on deep comparison of its dependencies
- useCustomCompareEffect — run an effect depending on deep comparison of its dependencies. (Implemented as useCustomCompareEffect)
State
-
createMemo — factory of memoized hooks.(Not planning to implement) -
createReducer — factory of reducer hooks with custom middleware.(Not planning to implement) -
createReducerContext — factory of hooks for a sharing state between components.(Not planning to implement) -
createStateContext — factory of hooks for a sharing state between components.(Not planning to implement) -
useDefault — returns the default value when state is null or undefined.(No plans to implement. Use useMediatedState instead). -
useGetSet — returns state getter get() instead of raw state.(No plans to implement) -
useGetSetState — as if useGetSet and useSetState had a baby.(No plans to implement) - useLatest — returns the latest state or props (Implemented as useSynchedRef)
- usePrevious — returns the previous state or props. (Implemented as usePrevious)
- usePreviousDistinct — like usePrevious but with a predicate to determine if previous should update. (Implemented as usePreviousDistinct)
- useObservable — tracks latest value of an Observable.
- useRafState — creates setState method which only updates after requestAnimationFrame.
-
useSetState — creates setState method which works like this.setState.(No plans to implement) - useStateList — circularly iterates over an array.
- useToggle — tracks state of a boolean. (Implemented as useToggle)
- useBoolean — tracks state of a boolean. (Implemented as useToggle)
- useCounter — tracks state of a number.
-
useNumber — tracks state of a number.(Implemented as useCounter) - useList — tracks state of an array.
-
useUpsert — tracks state of an array.(UseuseList
instead.) - useMap — tracks state of an object. (Implemented as useMap)
- useSet — tracks state of a Set. (Implemented as useSet)
- useQueue — implements simple queue. (Implemented as useQueue)
- useStateValidator — tracks state of an object.
- useStateWithHistory — stores previous state values and provides handles to travel through them.
- useMultiStateValidator — alike the useStateValidator, but tracks multiple states at a time.
- useMediatedState — like the regular useState but with mediation by custom function. (Implemented as useMediatedState)
- useFirstMountState — check if current render is first. (Implemented as useFirstMountState)
-
useRendersCount — count component renders.(Implemented asuseRenderCount
). -
createGlobalState — cross component shared state.(Not planning to implement) -
useMethods — neat alternative to useReducer.(No plans to implement)
Miscellaneous
- useEnsuredForwardedRef — use a React.forwardedRef safely.
- ensuredForwardRef — use a React.forwardedRef safely.
Join our community!
Have a question? Create a discussion on GitHub or join our Discord community.
Interested in contributing code? Check out our contribution guide. We are excited to see your pull request!
himself65 and arsinclair
Metadata
Metadata
Labels
good first issueGood for newcomersGood for newcomers✨ enhancementNew feature or requestNew feature or request🆘 help wantedExtra attention is neededExtra attention is needed🎂 new hookNew hook addedNew hook added