A collection of essential React hooks designed for both React and Voby environments. This library provides a set of utility hooks that help you build better applications with less code.
# Using npm
npm install @woby/use
# Using yarn
yarn add @woby/use
# Using pnpm
pnpm add @woby/useimport { useToggle, useCounter, useLocalStorage } from '@woby/use';
function MyComponent() {
const [value, toggle] = useToggle(false);
const { count, increment, decrement } = useCounter(0);
const [name, setName] = useLocalStorage('name', '');
return (
<div>
<p>Toggle value: {() => $(value) ? 'ON' : 'OFF'}</p>
<button onClick={toggle}>Toggle</button>
<p>Count: {count}</p>
<button onClick={increment}>+</button>
<button onClick={decrement}>-</button>
<input
value={name}
onChange={(e) => setName(e.target.value)}
placeholder="Enter your name"
/>
</div>
);
}use- Convert values to observables with optional cloning
useBoolean- Tracks state of a boolean valueuseCounter- Tracks numerical state with increment/decrement functionsuseToggle- Toggles between two valuesuseMap- Tracks state of a MapuseSet- Tracks state of a SetuseStep- Manages step navigationuseCountdown- Manages countdown timers
useLocalStorage- Manages localStorage valuesuseSessionStorage- Manages sessionStorage valuesuseReadLocalStorage- Reads localStorage valuesuseWindowSize- Tracks window size changesuseAspect- Calculates window aspect ratiouseViewportSize- Accesses visual viewport propertiesuseDarkMode- Tracks and toggles dark mode stateuseTernaryDarkMode- Advanced dark mode managementuseMediaQuery- Tracks media query matchesuseCopyToClipboard- Copies text to clipboarduseDocumentTitle- Sets the document titleuseLockedBody- Locks body scrollinguseElementSize- Tracks element sizeuseIntersectionObserver- Observes element intersectionsuseImageOnLoad- Handles image loadinguseScreen- Accesses screen informationuseGpsLocation- Accesses GPS locationuseLocation- Accesses browser locationuseScreenOrientation- Accesses screen orientationuseSelection- Accesses text selection
useEventListener- Subscribes to eventsuseClickAnyWhere- Subscribes a callback to clicks anywhere on the pageuseClickAway- Detects clicks outside an elementuseOnClickOutside- Detects clicks outside an element
useDebounce- Debounces a value or functionuseTimeout- Sets up a timeout that runs a callbackuseInterval- Sets up an interval that runs a callbackuseIsomorphicLayoutEffect- useLayoutEffect in browser, useEffect in serveruseEffectOnce- Runs an effect only onceuseUpdateEffect- Runs an effect on updates only
useFetch- Fetches data from a URLuseScript- Loads external scriptsuseHover- Tracks hover state of an elementuseDestruct- Destructures objects and arraysuseEventCallback- Creates stable event callbacksuseId- Generates unique IDsuseInvert- Inverts boolean valuesusePause- Creates timed delaysuseTimer- Creates timersuseTry- Executes functions with error handling
useSsr- Handles server-side renderinguseIsClient- Checks if running on clientuseIsFirstRender- Checks if it's the first renderuseIsMounted- Checks if component is mounted
Check out our full documentation for detailed information about each hook:
# Clone the repository
git clone https://github.com/wobyjs/use
cd @woby/use
# Install dependencies
pnpm install
# Start development server
pnpm dev
# Build for production
pnpm build:web
# Run tests
pnpm test
# Serve documentation
pnpm docsThe hooks in this library are designed to work with:
- React (16.8+)
- Voby (with appropriate JSX configuration)
All hooks come with full TypeScript support and type definitions included.
Contributions are welcome! Please read our contributing guide to get started.
MIT