Shadcn Hooks

useControllableValue

A hook to manage a controllable value

Loading...

Installation

npx shadcn@latest add @shadcnhooks/use-controllable-value

API

export interface Options<T> {
  defaultValue?: T
  defaultValuePropName?: string
  valuePropName?: string
  trigger?: string
}

export type Props = Record<string, any>

export interface StandardProps<T> {
  value: T
  defaultValue?: T
  onChange: (val: T) => void
}

/**
 * A hook to manage a controllable value
 * @param props - The props object containing value, defaultValue, and onChange
 */
function useControllableValue<T = any>(
  props: StandardProps<T>,
): [T, (v: SetStateAction<T>) => void]
function useControllableValue<T = any>(
  props?: Props,
  options?: Options<T>,
): [T, (v: SetStateAction<T>, ...args: any[]) => void]

Credits

Last updated on

On this page