Skip to content
aq-ui
Back to HooksHook

Use Controllable State

Open-code aq-ui React hook for Use Controllable State.

Installation

pnpm dlx aq-ui@alpha add use-controllable-state

API reference

Client module

Import the parts you need, then jump to an export for its contract.

View full source

Quick start

"use client"

import { useControllableState } from "@/hooks/use-controllable-state"

ControllableStateUpdater

typeSource L7

Type contract for ControllableStateUpdater.

type ControllableStateUpdater<T> = T | ((previous: T) => T)

useControllableState

functionSource L15

Open-code aq-ui React hook for Use Controllable State.

function useControllableState<T>({ value, defaultValue, onChange, }: UseControllableStateOptions<T>): [ T, (next: ControllableStateUpdater<T>) => void, ]
Returns
[ T, (next: ControllableStateUpdater<T>) => void, ]

Parameters

NameType
optionsUseControllableStateOptions<T>

UseControllableStateOptions

interfaceSource L9

Type contract for UseControllableStateOptions.

interface UseControllableStateOptions<T>

Members

NameType
value?T
defaultValueT | (() => T)
onChange?(value: T) => void

Registry dependencies

use-latest

Files

  • hooks/use-controllable-state.ts

Source