This library provides a set of custom React hooks that help simplify common patterns and interactions in React applications. These hooks aim to improve code reusability, readability, and maintainability.
Note: This package is currently only available via GitHub Packages.
-
Generate a GitHub personal access token with
read:packagesscope:- Go to GitHub Settings → Personal Access Tokens
- Generate a new token with at least the
read:packagespermission - Copy the token value
-
Create or update your
.npmrcfile in your project root or home directory:
@kaelui:registry=https://npm.pkg.github.com
//npm.pkg.github.com/:_authToken=YOUR_GITHUB_TOKEN
- Install the package:
pnpm add @kaelui/hooks- useDisclosure: manages disclosure state (open/closed).
- useResizeObserver: uses
ResizeObserverto track changes in element dimensions. - useMediaQuery: subscribe and respond to media query changes.
- useMounted: returns
trueif component is mounted. - useDidUpdate: executes a callback function when dependencies change, but skips the initial mount effect.
- useLogger: automatically logs specified values to the console on each component render for debugging.
- useWindowEvent: adds an event listener to the window object.
- useReducedMotion: detects if the user has requested reduced motion.
- useScrollIntoView: smoothly scrolls an element into view with customizable animation, alignment, and other options.
- useLongPress: detects long press gestures on mouse and touch events with customizable threshold and callbacks.
To create a new hook with all the required files, run:
pnpm create-hookThis will prompt you for a hook name and description, then automatically generate necessary files.
MIT