@itwin/itwinui-react
Version:
A react component library for iTwinUI
14 lines (13 loc) • 664 B
TypeScript
import * as React from 'react';
/**
* 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`.
*
* @example
* const [state, setState] = useControlledState(null, props.value, props.onChange);
*/
export declare const useControlledState: <T>(initialValue: T, controlledState: T | undefined, setControlledState?: React.Dispatch<React.SetStateAction<T>>) => readonly [T, React.Dispatch<React.SetStateAction<T>>];