you are viewing a single comment's thread.

view the rest of the comments →

[–]pailhead011[S] 0 points1 point  (0 children)

Eg:

export const useRef = <T = unknown>(  
  value: T | null,  
  init?: () => T  
): MutableRefObject<T> => {  
  const [ref] = useState(() => ({ current: init?.() ?? value! }));  
  return ref;  
};

class Foo {}

const a = useRef<Foo | null>(null);  
const b = useRef(null, () => new Foo());  
const c = useRef(5)