import * as React from "react";

export const SuspenseContext = React.createContext(false);
export const useSuspenseContext = () => React.use(SuspenseContext);

export const MaybeSuspend = ({ children }: { children: React.ReactNode }) => {
  const alreadyInSuspense = useSuspenseContext();
  return alreadyInSuspense ? (
    <>{children}</>
  ) : (
    <React.Suspense fallback={null}>{children}</React.Suspense>
  );
};
