mirror of
https://github.com/vector-im/element-call.git
synced 2024-11-15 00:04:59 +08:00
Merge branch 'livekit' into fkwp-patch-1
This commit is contained in:
commit
c412e2550d
@ -1,5 +1,5 @@
|
||||
/*
|
||||
Copyright 2023 New Vector Ltd
|
||||
Copyright 2023-2024 New Vector Ltd
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
@ -14,18 +14,17 @@ See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
import { useEffect, useRef } from "react";
|
||||
import { useRef } from "react";
|
||||
import { BehaviorSubject, Observable } from "rxjs";
|
||||
|
||||
/**
|
||||
* React hook that creates an Observable from a changing value. The Observable
|
||||
* replays its current value upon subscription, emits whenever the value
|
||||
* changes, and completes when the component is unmounted.
|
||||
* replays its current value upon subscription and emits whenever the value
|
||||
* changes.
|
||||
*/
|
||||
export function useObservable<T>(value: T): Observable<T> {
|
||||
const subject = useRef<BehaviorSubject<T>>();
|
||||
subject.current ??= new BehaviorSubject(value);
|
||||
if (value !== subject.current.value) subject.current.next(value);
|
||||
useEffect(() => subject.current!.complete(), []);
|
||||
return subject.current;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user