mirror of
https://github.com/vector-im/element-call.git
synced 2026-02-26 05:17:04 +00:00
Rename error boundary hook
It doesn't check whether it's actually used inside a GroupCallErrorBoundary, and it's generally useful for interacting with any error boundary, so I'm giving it a generic name to reflect this.
This commit is contained in:
29
src/useErrorBoundary.ts
Normal file
29
src/useErrorBoundary.ts
Normal file
@@ -0,0 +1,29 @@
|
||||
/*
|
||||
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.
|
||||
*/
|
||||
|
||||
import { useMemo, useState } from "react";
|
||||
|
||||
export type UseErrorBoundaryApi = {
|
||||
showErrorBoundary: (error: Error) => void;
|
||||
};
|
||||
|
||||
export function useErrorBoundary(): UseErrorBoundaryApi {
|
||||
const [error, setError] = useState<Error | null>(null);
|
||||
|
||||
const memoized: UseErrorBoundaryApi = useMemo(
|
||||
() => ({
|
||||
showErrorBoundary: (error: Error) => setError(error),
|
||||
}),
|
||||
[],
|
||||
);
|
||||
|
||||
if (error) {
|
||||
throw error;
|
||||
}
|
||||
|
||||
return memoized;
|
||||
}
|
||||
Reference in New Issue
Block a user