@volvo-cars/react-utils
v1.3.0
Published
Common and general React hooks
Keywords
Readme
@volvo-cars/react-utils
A collection of general-purpose React hooks and utilities that don't belong to a more specific package.
What's included
usePrevious— Returns the previous value of a prop or state variable after a re-render. Useful for comparing before/after values in effectsuseKeyPress— Attaches akeydownevent listener on mount and calls the provided callback when any of the specified key(s) are pressed. Accepts an array of key names or a legacy comma- or space-delimited stringuseInterval— Sets up asetIntervalthat is automatically cleared on unmount. Accepts a callback and a delay in millisecondsuseComposedRefs/composeRefs— Merges multiple React refs (callback refs or ref objects) into a single ref. Useful when a component needs to forward a ref while also using one internallyuseDismiss— Controls the visibility and dismissal state of a dismissible element, with optional persistence across the browser session via the Cookie Store API
Installation
yarn add @volvo-cars/react-utils