@volvo-cars/react-utils
v1.2.1
Published
Common and general React hooks
Readme
React Utils
Questions? Ask in Slack #vcc-ui
@volvo-cars/react-utils
This package exposes useful generic hooks that don't belong to a hook collection (like react-layout-utils)
Installation
💡 This package includes Typescript definitions
usePrevious
Returns the previous value of a passed prop or state.
| Name | Description | Type | Default Value |
| ------- | ------------------------------------------------------------------ | --------- | ------------- |
| value | The property you wish to know the previous state of post re-render | unknown | undefined |
useKeyPress
Adds an event listener on component mount that invokes the provided callback function on matching key(s)press.
useKeyPress('Escape', () => console.log('Escape key pressed!')| Name | Description | Type | Default Value |
| ---------------- | -------------------------------------------------- | -------- | ------------- |
| keysToListenTo | Comma or space delimited list of keys to listen to | string | undefined |
| callback | Function to be invoked on keypress | func | undefined |
