refactor(v2): do not use announcement bar hook unnecessarily

This commit is contained in:
Alexey Pyltsyn 2020-05-27 18:42:36 +03:00
parent aaa8423c35
commit 9973ae2d12

View file

@ -13,11 +13,7 @@ const STORAGE_ID_KEY = 'docusaurus.announcement.id';
const useAnnouncementBar = () => { const useAnnouncementBar = () => {
const { const {
siteConfig: { siteConfig: {themeConfig: {announcementBar: {id} = {}}} = {},
themeConfig: {
announcementBar: {id},
},
} = {},
} = useDocusaurusContext(); } = useDocusaurusContext();
const [isClosed, setClosed] = useState(true); const [isClosed, setClosed] = useState(true);
const handleClose = () => { const handleClose = () => {
@ -26,6 +22,10 @@ const useAnnouncementBar = () => {
}; };
useEffect(() => { useEffect(() => {
if (!id) {
return;
}
const viewedId = localStorage.getItem(STORAGE_ID_KEY); const viewedId = localStorage.getItem(STORAGE_ID_KEY);
const isNewAnnouncement = id !== viewedId; const isNewAnnouncement = id !== viewedId;