Skip to content

🤯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.

245 B
Raw Blame
import { useRef } from 'react';

export const useSingleton = <T>(factory: () => T): T => {
  const ref = useRef<{ value: T } | null>(null);
  if (ref.current === null) {
    ref.current = { value: factory() };
  }
  return ref.current.value;
};