BlockDex

Components

Registries

Free blocks

Method

BlockDex

Components

Registries

Free blocks

Method

Open API

BlockDex

Components

Registries

Free blocks

Method

Open API

Components/shadcn-hooks/use-controllable-value

use-controllable-value

shadcn-hooks/use-controllable-value
FreeHook

A hook to manage a controllable value

Install it

npx shadcn@latest add https://shadcn-hooks.com/r/use-controllable-value.json

Source

registry/hooks/use-controllable-value.tsshadcn-hooks.com/r/use-controllable-value.json
1import { isFunction } from 'es-toolkit/predicate'
2import { useMemo, useRef } from 'react'
3import { useMemoizedFn } from '@/registry/hooks/use-memoized-fn'
4import { useUpdate } from '@/registry/hooks/use-update'
5import type { SetStateAction } from 'react'
6
7export interface Options<T> {
8 defaultValue?: T
9 defaultValuePropName?: string
10 valuePropName?: string
11 trigger?: string
12}
13
14export type Props = Record<string, any>
15
16export interface StandardProps<T> {
17 value: T
18 defaultValue?: T
19 onChange: (val: T) => void
20}
21
22function useControllableValue<T = any>(
23 props: StandardProps<T>,
24): [T, (v: SetStateAction<T>) => void]
25function useControllableValue<T = any>(
26 props?: Props,
27 options?: Options<T>,
28): [T, (v: SetStateAction<T>, ...args: any[]) => void]
29function useControllableValue<T = any>(
30 defaultProps?: Props,
31 options: Options<T> = {},
32) {
33 const props = defaultProps ?? {}
34
35 const {
36 defaultValue,
37 defaultValuePropName = 'defaultValue',
38 valuePropName = 'value',
39 trigger = 'onChange',
40 } = options
41
42 const value = props[valuePropName] as T
43 const isControlled = Object.prototype.hasOwnProperty.call(
44 props,
45 valuePropName,
46 )
47
48 const initialValue = useMemo(() => {
49 if (isControlled) {
50 return value
51 }
52 if (Object.prototype.hasOwnProperty.call(props, defaultValuePropName)) {
53 return props[defaultValuePropName]
54 }
55 return defaultValue
56 }, [])
57
58 const stateRef = useRef(initialValue)
59 if (isControlled) {
60 stateRef.current = value
61 }
62
63 const update = useUpdate()
64
65 const setState = (v: SetStateAction<T>, ...args: any[]) => {
66 const r = isFunction(v) ? v(stateRef.current) : v
67
68 if (!isControlled) {
69 stateRef.current = r
70 update()
71 }
72 if (props[trigger]) {
73 props[trigger](r, ...args)
74 }
75 }
76
77 return [stateRef.current, useMemoizedFn(setState)] as const
78}
79
80export { useControllableValue }

What it pulls in

npm packages

  • es-toolkit

Other registry items

  • @shadcnhooks/use-memoized-fn
  • @shadcnhooks/use-update

Files it writes

  • registry/hooks/use-controllable-value.ts

Facts

Registry
shadcn-hooks
Type
registry:hook
Access
Free
Files written
1
Licence
the repository states none
In the index
at or before 2026-08-08
Last confirmed
today

Go to the source

shadcn-hooks.com Debbl/shadcn-hooks on GitHub Raw registry item This item as JSON

More from shadcn-hooks

All 58 items
Same registry, same kind — the ones you would have found next
ComponentRegistryKindAccessInstallsCommand
use-active-elementuse-active-elementshadcn-hooksHooksFreeno deps
use-batteryuse-batteryshadcn-hooksHooksFreeno deps
use-booleanuse-booleanshadcn-hooksHooksFreeno deps
use-click-any-whereuse-click-any-whereshadcn-hooksHooksFreeno deps
use-click-awayuse-click-awayshadcn-hooksHooksFreeno deps
use-clipboarduse-clipboardshadcn-hooksHooksFreeno deps
use-counteruse-countershadcn-hooksHooksFreeno deps
use-creationuse-creationshadcn-hooksHooksFree1 dep

Also from Kynth Studios

Built for the same person as BlockDex

SkillWorks

Claude Code skills and plugins, scored

skillworks.kynth.studio

RuleStack

AGENTS.md gallery and agent-config comparison

rulestack.kynth.studio

ToolDrift

What the AI coding tools changed last night

tooldrift.kynth.studio

The studio list

One product, taken apart, once a month

Kynth Studios pulls one shipped product open every month — what it does, what it cost to build, what the pipeline behind it looks like, and what the numbers did. One email a month, nothing in between.

Double opt-in — we send one confirmation link and nothing else until you click it.

BlockDex

Built by

Kynth Studios

the studio behind SkillWorks, RuleStack and ToolDrift

part of Toolproof, the measurement layer for AI agent tooling

Index

Components
Registries
Method
Open API

Guides

shadcn component libraries
Best shadcn registries
Free shadcn blocks

Reference

Corpus counts
Crawl health
hello@kynth.studio
Privacy
Terms

© 2026 BlockDex. A Kynth Studios product. Changelog

BlockDex

The studio list

One product, taken apart, once a month

Kynth Studios pulls one shipped product open every month — what it does, what it cost to build, what the pipeline behind it looks like, and what the numbers did. One email a month, nothing in between.

Double opt-in — we send one confirmation link and nothing else until you click it.

BlockDex

Built by

Kynth Studios

the studio behind SkillWorks, RuleStack and ToolDrift

part of Toolproof, the measurement layer for AI agent tooling

Index

Components
Registries
Method
Open API

Guides

shadcn component libraries
Best shadcn registries
Free shadcn blocks

Reference

Corpus counts
Crawl health
hello@kynth.studio
Privacy
Terms

© 2026 BlockDex. A Kynth Studios product. Changelog

BlockDex

The studio list

One product, taken apart, once a month

Kynth Studios pulls one shipped product open every month — what it does, what it cost to build, what the pipeline behind it looks like, and what the numbers did. One email a month, nothing in between.

Double opt-in — we send one confirmation link and nothing else until you click it.

BlockDex

Built by

Kynth Studios

the studio behind SkillWorks, RuleStack and ToolDrift

part of Toolproof, the measurement layer for AI agent tooling

Index

Components
Registries
Method
Open API

Guides

shadcn component libraries
Best shadcn registries
Free shadcn blocks

Reference

Corpus counts
Crawl health
hello@kynth.studio
Privacy
Terms

© 2026 BlockDex. A Kynth Studios product. Changelog

BlockDex