import * as React from "react";
import { useHydrated } from "./use-hydrated.js";
/**
 * Render the children only before the JS has loaded client-side. Use an
 * optional fallback component for once the JS has loaded.
 *
 * Example: Render a hidden input to identify if the user has JS.
 * ```tsx
 * return (
 *   <ServerOnly fallback={<FakeChart />}>
 *     {() => <Chart />}
 *   </ServerOnly>
 * );
 * ```
 */
export function ServerOnly({ children, fallback = null }) {
  return useHydrated()
    ? React.createElement(React.Fragment, null, fallback)
    : React.createElement(React.Fragment, null, children());
}
