Type fixes for react v19 compatibility (#2937)

This commit is contained in:
Hugh Nimmo-Smith
2025-01-13 14:54:42 +00:00
committed by GitHub
parent c8b30dd8a7
commit 2f5f0978ad
17 changed files with 33 additions and 14 deletions

View File

@@ -11,7 +11,8 @@ import { useRef } from "react";
* React hook that returns the value given on the initial render.
*/
export function useInitial<T>(getValue: () => T): T {
const ref = useRef<{ value: T }>();
const ref = useRef<{ value: T }>(undefined);
// only evaluate `getValue` if the ref is undefined
ref.current ??= { value: getValue() };
return ref.current.value;
}