use-creation
shadcn-hooks/use-creationFreeHook
A hook to create a value only once
Install it
npx shadcn@latest add https://shadcn-hooks.com/r/use-creation.jsonSource
1import { isEqual } from 'es-toolkit/predicate'2import { useRef } from 'react'3import type { DependencyList } from 'react'45export function useCreation<T>(factory: () => T, deps: DependencyList) {6 const { current } = useRef({7 deps,8 obj: undefined as T,9 initialized: false,10 })1112 if (current.initialized === false || !isEqual(current.deps, deps)) {13 current.deps = deps14 current.obj = factory()15 current.initialized = true16 }1718 return current.obj19}
What it pulls in
npm packages
Files it writes
More from shadcn-hooks
All 58 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| use-active-elementuse-active-element | shadcn-hooks | Hooks | Free | no deps | |
| use-batteryuse-battery | shadcn-hooks | Hooks | Free | no deps | |
| use-booleanuse-boolean | shadcn-hooks | Hooks | Free | no deps | |
| use-click-any-whereuse-click-any-where | shadcn-hooks | Hooks | Free | no deps | |
| use-click-awayuse-click-away | shadcn-hooks | Hooks | Free | no deps | |
| use-clipboarduse-clipboard | shadcn-hooks | Hooks | Free | no deps | |
| use-controllable-valueuse-controllable-value | shadcn-hooks | Hooks | Free | 1 dep | |
| use-counteruse-counter | shadcn-hooks | Hooks | Free | no deps |
