Registry-Entscheidung evidenzbasiert: das Package ist pnpm-Dependency von ThreadNet-Webs apps/web, der Lockfile pinnt die Tarball-URL auf rohana - Registry bleibt dort. Publish-Auth ueber CI-Variable GITEA_NPM_TOKEN statt lokaler Klartext-.npmrc. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
26 lines
712 B
TypeScript
26 lines
712 B
TypeScript
/*
|
|
Copyright 2025 New Vector Ltd.
|
|
|
|
SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial
|
|
Please see LICENSE in the repository root for full details.
|
|
*/
|
|
|
|
import { useCallback, useSyncExternalStore } from "react";
|
|
|
|
import { type Behavior } from "./state/Behavior";
|
|
|
|
/**
|
|
* React hook which reactively reads the value of a behavior.
|
|
*/
|
|
export function useBehavior<T>(behavior: Behavior<T>): T {
|
|
const subscribe = useCallback(
|
|
(onChange: () => void) => {
|
|
const s = behavior.subscribe(onChange);
|
|
return (): void => s.unsubscribe();
|
|
},
|
|
[behavior],
|
|
);
|
|
const getValue = useCallback(() => behavior.value, [behavior]);
|
|
return useSyncExternalStore(subscribe, getValue);
|
|
}
|