2022-04-27 09:14:44 +02:00
|
|
|
import { useEffect, useContext } from 'react';
|
|
|
|
import { AnnouncerContext } from 'component/common/Announcer/AnnouncerContext/AnnouncerContext';
|
|
|
|
|
2022-06-21 09:08:37 +02:00
|
|
|
export const usePageTitle = (title?: string) => {
|
2022-04-27 09:14:44 +02:00
|
|
|
const { setAnnouncement } = useContext(AnnouncerContext);
|
|
|
|
|
|
|
|
useEffect(() => {
|
2022-06-21 09:08:37 +02:00
|
|
|
if (title) {
|
|
|
|
document.title = title;
|
|
|
|
return () => {
|
|
|
|
document.title = DEFAULT_PAGE_TITLE;
|
|
|
|
};
|
|
|
|
}
|
2022-04-27 09:14:44 +02:00
|
|
|
}, [title]);
|
|
|
|
|
|
|
|
useEffect(() => {
|
2022-06-21 09:08:37 +02:00
|
|
|
if (title && title !== DEFAULT_PAGE_TITLE) {
|
2022-04-27 09:14:44 +02:00
|
|
|
setAnnouncement(`Navigated to ${title}`);
|
|
|
|
}
|
|
|
|
}, [setAnnouncement, title]);
|
|
|
|
};
|
|
|
|
|
|
|
|
const DEFAULT_PAGE_TITLE = 'Unleash';
|