BlockDex

Components

Registries

Free blocks

Method

BlockDex

Components

Registries

Free blocks

Method

Open API

BlockDex

Components

Registries

Free blocks

Method

Open API

Components/billui/use-controllable-state

Use Controllable State

billui/use-controllable-state
FreeUtility

Use Controllable State component

Live preview

live · rendered by the registry
Rendered by billui on their own page — this is the component running, not a screenshot of it.

Install it

npx shadcn@latest add https://billui.com/r/use-controllable-state.json

Source

src/registry/lib/use-controllable-state.tsbillui.com/r/use-controllable-state.json
1"use client";
2
3import * as React from "react";
4
5/**
6 * Hook for components that support both controlled and uncontrolled modes.
7 *
8 * @param controlledValue - The controlled value (if provided)
9 * @param defaultValue - The default value for uncontrolled mode
10 * @param onChange - Callback fired when value changes
11 * @returns A tuple of [currentValue, setValue]
12 *
13 * @example
14 * ```tsx
15 * interface Props {
16 * value?: string;
17 * defaultValue?: string;
18 * onValueChange?: (value: string) => void;
19 * }
20 *
21 * function Input({ value, defaultValue = "", onValueChange }: Props) {
22 * const [currentValue, setValue] = useControllableState(
23 * value,
24 * defaultValue,
25 * onValueChange,
26 * );
27 *
28 * return (
29 * <input
30 * value={currentValue}
31 * onChange={(e) => setValue(e.target.value)}
32 * />
33 * );
34 * }
35 * ```
36 */
37export function useControllableState<T>(
38 controlledValue: T | undefined,
39 defaultValue: T,
40 onChange?: (value: T) => void,
41): [T, (value: T) => void] {
42 const [internalValue, setInternalValue] = React.useState(defaultValue);
43 const isControlled = controlledValue !== undefined;
44 const value = isControlled ? controlledValue : internalValue;
45
46 const setValue = React.useCallback(
47 (newValue: T) => {
48 if (!isControlled) {
49 setInternalValue(newValue);
50 }
51 onChange?.(newValue);
52 },
53 [isControlled, onChange],
54 );
55
56 return [value, setValue];
57}

Files it writes

  • src/registry/lib/use-controllable-state.ts

Facts

Registry
billui
Type
registry:lib
Access
Free
Files written
1
Licence
MIT
First indexed
2026-08-02
Last confirmed
yesterday

Go to the source

Docs on billui billui.com commet-labs/billui on GitHub Raw registry item This item as JSON

More from billui

All 13 items
Same registry, same kind — the ones you would have found next
ComponentRegistryKindAccessInstallsCommand
Billing Address Databilling-address-databilluiUtilitiesFreeno deps
UtilsutilsbilluiUtilitiesFree2 deps
BlockDex

Built by

Kynth Studio

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

BlockDex

BlockDex

Built by

Kynth Studio

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

BlockDex

BlockDex

Built by

Kynth Studio

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

BlockDex