mirror of
https://github.com/Unleash/unleash.git
synced 2024-11-01 19:07:38 +01:00
22 lines
618 B
TypeScript
22 lines
618 B
TypeScript
|
import { useEffect, useContext } from 'react';
|
||
|
import { AnnouncerContext } from 'component/common/Announcer/AnnouncerContext/AnnouncerContext';
|
||
|
|
||
|
export const usePageTitle = (title: string) => {
|
||
|
const { setAnnouncement } = useContext(AnnouncerContext);
|
||
|
|
||
|
useEffect(() => {
|
||
|
document.title = title;
|
||
|
return () => {
|
||
|
document.title = DEFAULT_PAGE_TITLE;
|
||
|
};
|
||
|
}, [title]);
|
||
|
|
||
|
useEffect(() => {
|
||
|
if (title !== DEFAULT_PAGE_TITLE) {
|
||
|
setAnnouncement(`Navigated to ${title}`);
|
||
|
}
|
||
|
}, [setAnnouncement, title]);
|
||
|
};
|
||
|
|
||
|
const DEFAULT_PAGE_TITLE = 'Unleash';
|