/*---------------------------------------------------------------------------------------------
 * Copyright (c) Bentley Systems, Incorporated. All rights reserved.
 * See LICENSE.md in the project root for license terms and full copyright notice.
 *--------------------------------------------------------------------------------------------*/
/** @packageDocumentation
 * @module State
 */
import { useCallback, useSyncExternalStore } from "react";
import { UiFramework } from "../UiFramework.js";
/* eslint-disable @typescript-eslint/no-deprecated */
/** @internal */
export function useReduxFrameworkState(selector) {
    const subscribe = useCallback((onStoreChange) => {
        const reduxStore = UiFramework.reduxStore;
        if (!reduxStore)
            return () => { };
        return reduxStore.subscribe(onStoreChange);
    }, []);
    const getSnapshot = useCallback(() => {
        const reduxStore = UiFramework.reduxStore;
        const state = reduxStore?.getState();
        const frameworkState = state?.[UiFramework.frameworkStateKey];
        return selector(frameworkState);
    }, [selector]);
    return useSyncExternalStore(subscribe, getSnapshot);
}
//# sourceMappingURL=useReduxFrameworkState.js.map