mirror of
https://github.com/element-hq/element-call.git
synced 2026-10-06 14:37:19 +00:00
With this change, views now read every reactive value through `useBehavior`, as `architecture.md` already prescribes. Where a view reads a plain stream, the view model now exposes a `Behavior`.
26 lines
793 B
TypeScript
26 lines
793 B
TypeScript
/*
|
|
Copyright 2026 Element Creations Ltd.
|
|
|
|
SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial
|
|
Please see LICENSE in the repository root for full details.
|
|
*/
|
|
|
|
import { useEffect } from "react";
|
|
import { BehaviorSubject } from "rxjs";
|
|
|
|
import { type Behavior } from "./state/Behavior";
|
|
import { useInitial } from "./useInitial";
|
|
|
|
/**
|
|
* React hook which mirrors a value from the render cycle into a behavior, so
|
|
* that a prop or memoised value can be handed to a view model. The behavior
|
|
* takes each new value once the render that produced it has committed.
|
|
*/
|
|
export function useValueBehavior<T>(value: T): Behavior<T> {
|
|
const value$ = useInitial(() => new BehaviorSubject(value));
|
|
useEffect(() => {
|
|
value$.next(value);
|
|
}, [value$, value]);
|
|
return value$;
|
|
}
|