/*---------------------------------------------------------------------------------------------
 * Copyright (c) Bentley Systems, Incorporated. All rights reserved.
 * See LICENSE.md in the project root for license terms and full copyright notice.
 *--------------------------------------------------------------------------------------------*/
import * as React from "react";
/** @internal */
export function useControlledState(initialValue, controlledState, setControlledState) {
    const [uncontrolledState, setUncontrolledState] = React.useState(initialValue);
    const state = React.useMemo(() => (controlledState !== undefined ? controlledState : uncontrolledState), [controlledState, uncontrolledState]);
    const setState = React.useCallback((value) => {
        setUncontrolledState(value);
        setControlledState?.(value);
    }, [setControlledState, setUncontrolledState]);
    return [state, setState];
}
//# sourceMappingURL=useControlledState.js.map