import { FunctionComponent } from "preact";
import { useEffect } from "preact/hooks";

export const withTitle = <P,>(title: string, WrappedComponent: FunctionComponent<P>): FunctionComponent<P> => {
  const ComponentWithTitle: FunctionComponent<P> = (props) => {
    useEffect(() => {
      document.title = title;
    }, []);
    return <WrappedComponent {...props} />;
  };
  return ComponentWithTitle;
};
