"use client";

import { useEffect, useState } from "react";

/**
 * Has this component hydrated on the client yet?
 *
 * The three carousels on the homepage each render a different tree on the
 * client than on the server — they measure `window.innerWidth` to decide how
 * many cards fit — so they hold the server-shaped output until hydration has
 * happened and only then switch. Rendering the measured version on the first
 * client pass instead would be a hydration mismatch.
 *
 * `setState` in a mount effect is the documented way to detect that
 * transition: the whole point is that the value must differ between the
 * server render and the first client render, which a lazy initializer cannot
 * express (it runs during render, in both environments). The
 * `react-hooks/set-state-in-effect` report on the line below is therefore
 * accepted, and it is accepted **once** here rather than three times — this
 * replaces identical copies in `CommunityCard`, `useEventCard` and
 * `useVolunteerCard`.
 */
export function useIsMounted(): boolean {
  const [isMounted, setIsMounted] = useState(false);

  useEffect(() => {
    setIsMounted(true);
  }, []);

  return isMounted;
}
