createSharedHook
One shared instance of the hook globally. First subscriber's args are used; when subscribers hit zero, the runner unmounts.
helpers
low
test coverage
Last changed: 23 seconds ago
WARNING
For complex interfaces, we strongly recommend using state management solutions outside of React like createStore, reatom, effector, or zustand instead of context
Installation
Library
CLI
Manual
typescript
import { createSharedHook } from '@siberiacancode/reactuse';Usage
typescript
const useSharedMediaQuery = createSharedHook(useMediaQuery); const matches = useSharedMediaQuery("(max-width: 768px)");Api
Parameters
| Name | Type | Default | Note |
|---|---|---|---|
| useHook | Hook | - | - The hook to create a shared instance of |
Returns
Hook & { useShared: typeof useShared }
Type declaration
typescript
type Value = ReturnType<Hook>;