UNPKG

@itwin/itwinui-react

Version:

A react component library for iTwinUI

17 lines (16 loc) 834 B
/** * Wrapper over `useState` that always gives preference to the * controlled state (which often comes from a prop). * * This is helpful when a component needs to support both uncontrolled * and controlled states. If controlled value/setter is not passed, * then it will work just like a regular `useState`. * The only exception is that the set function only accepts the new state. It does not accept a function. * * **NOTE**: `setControlledState` is called only when the value *changes* (uncontrolled mode) or should *change* * (controlled mode). * * @example * const [state, setState] = useControlledState(null, props.value, props.onChange); */ export declare const useControlledState: <T>(initialValue: T, controlledState: T | undefined, setControlledState?: (value: T) => void) => readonly [T, (value: T) => void];