import { useRef, useEffect } from 'atomico';

function useDocumentTitleHook(title, retainOnUnmount = false) {
  const defaultTitle = useRef(document.title);

  useEffect(() => {
    document.title = title;

    return () => {
      if (!retainOnUnmount) document.title = defaultTitle.current;
    };
  }, [title]);
}

export { useDocumentTitleHook };
