State Management

useControllableState

Create components that support both controlled and uncontrolled state patterns.

import { useControllableState } from "saha-ui"

Uses

Simplify components that can be either controlled or uncontrolled by providing a single API to read and update value while calling `onChange` when appropriate.

Props

NameTypeDescriptionDefault
defaultValueanyDefault for uncontrolled mode.-
valueanyControlled value (optional).-
onChangefunctionCallback when value changes.-

Returns

NameDescription
[currentValue, setValue]Current value and setter that respects controlled/uncontrolled behavior and calls `onChange`.

Example

const [value, setValue] = useControllableState('a', props.value, props.onChange);

Notes

Internal state syncs to controlled value when provided; setter updates internal state only when uncontrolled.
Saha UI - The Modern React Component Library