Archived
Type caught errors as unknown in the frontend
Replace `catch (e: any)` with `catch (e)` and read the message through a new errorMessage() helper. ApiError.data gets a real type, and useDismissingState's setter keeps one identity across renders. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -9,14 +9,17 @@ import { useCallback, useEffect, useRef, useState } from "react";
|
||||
export function useDismissingState<T>(initial: T, ms = 7000) {
|
||||
const [value, setValue] = useState<T>(initial);
|
||||
const timeoutRef = useRef<ReturnType<typeof setTimeout> | null>(null);
|
||||
// Held in a ref so the setter keeps one identity across renders (like useState's),
|
||||
// even when the caller passes a fresh object/array literal as `initial`.
|
||||
const initialRef = useRef(initial);
|
||||
|
||||
const set = useCallback((next: T) => {
|
||||
if (timeoutRef.current) clearTimeout(timeoutRef.current);
|
||||
setValue(next);
|
||||
if (next) {
|
||||
timeoutRef.current = setTimeout(() => setValue(initial), ms);
|
||||
timeoutRef.current = setTimeout(() => setValue(initialRef.current), ms);
|
||||
}
|
||||
}, [ms, initial]);
|
||||
}, [ms]);
|
||||
|
||||
useEffect(() => () => { if (timeoutRef.current) clearTimeout(timeoutRef.current); }, []);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user