import { createContext, useContext } from 'react';
import type { InitialProps } from './InitialProps';

export const InitialPropsContext = createContext<InitialProps | null>(null);

export function useInitialProps() {
  const initialProps = useContext(InitialPropsContext);

  if (initialProps == null) {
    throw new Error('InitialPropsContext is not initialized');
  }

  return initialProps;
}
