Type fixes for react v19 compatibility (#2937)
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user