2025-03-10 15:20:51 +01:00
|
|
|
/*
|
|
|
|
|
Copyright 2023, 2024 New Vector Ltd.
|
|
|
|
|
|
|
|
|
|
SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial
|
|
|
|
|
Please see LICENSE in the repository root for full details.
|
|
|
|
|
*/
|
|
|
|
|
|
2025-03-17 11:26:16 +01:00
|
|
|
import { useMemo, useState } from "react";
|
2025-03-10 15:20:51 +01:00
|
|
|
|
|
|
|
|
import type { ElementCallError } from "../utils/errors.ts";
|
|
|
|
|
|
|
|
|
|
export type UseErrorBoundaryApi = {
|
|
|
|
|
showGroupCallErrorBoundary: (error: ElementCallError) => void;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export function useGroupCallErrorBoundary(): UseErrorBoundaryApi {
|
|
|
|
|
const [error, setError] = useState<ElementCallError | null>(null);
|
|
|
|
|
|
|
|
|
|
const memoized: UseErrorBoundaryApi = useMemo(
|
|
|
|
|
() => ({
|
|
|
|
|
showGroupCallErrorBoundary: (error: ElementCallError) => setError(error),
|
|
|
|
|
}),
|
|
|
|
|
[],
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
if (error) {
|
|
|
|
|
throw error;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return memoized;
|
|
|
|
|
}
|