import { useLayoutEffect, useState } from 'react';

/**
 * Returns false on the layout's first commit and true right after (before paint).
 *
 * Layouts add body classes / CSS variables in layout effects; rendering the page only
 * once they are applied lets widgets that measure on mount (ApexCharts, sticky headers)
 * see the final layout. Declare this hook after the layout's body-class effects.
 */
export function useLayoutReady(): boolean {
  const [ready, setReady] = useState(false);

  useLayoutEffect(() => {
    setReady(true);
  }, []);

  return ready;
}
