reactuse
repository·main·Indexed 19 days ago
https://github.com/siberiacancode/reactuseA toolset for managing React hooks, featuring the useverse CLI to streamline adding hooks and utilities to projects. It includes a registry for automatic dependency management, a configuration system via reactuse.json, and a collection of TypeScript-first, SSR-compatible hooks such as useCounter and useCookie. The package also provides @siberiacancode/eslint for generating Flat Config objects and predefined breakpoint configurations for various CSS frameworks.
What's inside reactuse
- Webcam React is a TypeScript-first library designed for integrating webcam and media stream features into React applications. It supports Server-Side Rendering (SSR) and is optimized for tree-shaking. It provides the necessary tools to request, display, and manage camera streams in modern React environments.
What the Reactuse skill provides
mainThe Reactuse skill is designed to optimize how AI coding assistants interact with the library. It provides:
- Hook-first decision model: Encourages using existing hooks before implementing custom logic.
- Invocation priority guidance: Categorizes hook usage into
HIGH,MEDIUM, orLOWpriority. - Domain-based coverage: Organizes hooks into structured domains including
async,browser,elements,lifecycle,state,utilities,sensors,time,user,debug, andhelpers. - Requirement mapping: Directly maps specific development requirements to concrete Reactuse APIs.
Explore @siberiacancode/reactuse hooks by usage level
mainThe
@siberiacancode/reactuselibrary organizes its hooks and helpers into four categories based on their practical utility and frequency of use in production applications:Necessary
Core primitives for everyday React tasks (e.g.,
useBoolean,useClickOutside,useMount,useEventListener).High
Frequently used functions for production features, including debouncing, storage management, and URL parameters (e.g.,
useDebounceValue,useLocalStorage,useUrlSearchParams,cn).Medium
Building blocks for specific recurring patterns like forms, pagination, intersection observers, and complex state management (e.g.,
useForm,useIntersectionObserver,useControllableState).Low
Niche utilities for specialized browser APIs, edge cases, and specific hardware interactions (e.g.,
useBluetooth,useBattery,useSpeechRecognition,useWebWorker).How createContextHook works
maincreateContextHookis a utility designed for scenarios where a hook needs to be configured differently for different parts of your application.Instead of calling a hook directly, you pass the hook function to
createContextHook. This returns aProvidercomponent. When you wrap a subtree with thisProviderand pass arguments via theparamsprop, the hook is executed with those arguments. Any component within that subtree can then call the returnedusehook to access the result of that specific hook execution.What the Reactuse skill provides to agents
mainThe
reactuseskill enhances an AI agent's ability to work with the library by providing:- Hook-first decision model: Encourages checking for existing hooks before writing custom logic.
- Invocation priority guidance: Categorizes hook usage with priority levels (
HIGH,MEDIUM,LOW). - Domain-based organization: Categorizes hooks into specific domains for easier retrieval:
asyncbrowserelementslifecyclestateutilitiessensorstimeuserdebughelpers
- Requirement mapping: Directly maps user requirements to concrete Reactuse APIs.
Understanding ReactUse's approach to memoization
mainReactUse deliberately avoids memoizing hook methods by default. The library follows the principle that memoization is an optimization technique that should be applied consciously by the developer rather than automatically by the library.
Why ReactUse avoids automatic memoization:
- Prevents masking architectural issues: Automatic memoization can hide the root causes of unnecessary re-renders instead of fixing them.
- Avoids false security: It prevents developers from assuming performance is optimized when it might not be.
- Simplifies debugging: Memoized functions can behave unexpectedly when dependencies change; by not memoizing by default, the library ensures more predictable behavior.
Developers are encouraged to use React's built-in tools like
useCallbackanduseMemoto manage performance manually when a real performance problem is identified.Understand the ReactUse optimization philosophy
mainReactUse prioritizes simple, predictable utility hooks. By default, the library does not implement shared caches or cross-component optimizations.
Each hook instance typically maintains its own subscription (e.g., one listener per hook call). This design choice ensures:
- Easier debugging: One subscription per hook instance with no hidden shared state.
- Reduced complexity: Avoids imposing shared stores on applications that do not require them.
Optimization is treated as a conscious, application-level decision. If you identify a performance bottleneck caused by many components using the same hook with the same arguments, you should implement optimization within your own application layer.
How flexible target handling works in @siberiacancode/reactuse
mainUnlike many React libraries that require you to manually create and pass a
ref,@siberiacancode/reactusehooks support two flexible ways to provide a target element:- Passing an existing target: You can pass a
ref, a direct DOM element, a function that returns a DOM element, or a CSS selector string. You can use thetargetutility to normalize these inputs. - Using a ref callback: You can call the hook without a target argument, and it will return a ref callback that you can attach directly to an element.
This approach allows you to use hooks with
querySelectoror existing DOM elements without the overhead of managing additionaluseRefinstances.import { useClickOutside } from '@siberiacancode/reactuse'; import { useRef } from 'react'; // Method 1: Passing an existing ref const ref = useRef<HTMLDivElement>(null); useClickOutside(ref, () => console.log('Clicked outside')); // Method 2: Using a ref callback (the hook returns the ref) const refCallback = useClickOutside<HTMLDivElement>(() => console.log('Clicked outside')); // <div ref={refCallback} />- Passing an existing target: You can pass a
Configure webcam mirroring and muting
mainThe webcam component supports horizontal mirroring and audio muting. Both are enabled by default.
mirrored: Flips the video and captured snapshots horizontally.muted: Mutes the underlying video element.
Understand ReactUse optimization philosophy
mainReactUse prioritizes simple, predictable utility hooks over automatic performance optimizations. By default, hooks do not include shared caches or cross-component optimizations (like shared listeners).
This design choice ensures:
- Predictability: One subscription per hook instance with no hidden shared state.
- Simplicity: Hooks are easier to reason about and debug.
- Efficiency: Optimization is treated as a conscious, application-level decision rather than a library-imposed overhead that affects all users.
Understand ReactUse's approach to memoization
mainReactUse deliberately avoids memoizing hook methods by default. The library follows a philosophy of conscious optimization rather than automatic memoization.
This approach is intended to:
- Prevent masking real architectural problems (like unnecessary re-renders).
- Avoid creating a false sense of performance security.
- Keep debugging predictable by ensuring functions behave as expected when dependencies change.
Developers are encouraged to use React's built-in tools like
useCallbackanduseMemoto apply memoization only where a real performance problem exists.Install useDeviceList
mainYou can install the
useDeviceListhook using the@siberiacancode/reactuselibrary, via theuseverseCLI, or by manually copying the source code into your project.# Via Library npm install @siberiacancode/reactuse # Via CLI npx useverse@latest add useDeviceList