mirror of
https://github.com/facebook/docusaurus.git
synced 2025-06-10 23:02:56 +02:00
refactor(core): replace useDocusaurusContext().isClient by useIsBrowser() (#5349)
* extract separate useIsClient() hook * for consistency, rename to `useIsBrowser` * useless return * improve doc for BrowserOnly * update snapshot * polish
This commit is contained in:
parent
69b11a8546
commit
295e77cc09
20 changed files with 213 additions and 90 deletions
|
@ -14,7 +14,7 @@ import React, {
|
|||
useContext,
|
||||
createContext,
|
||||
} from 'react';
|
||||
import useDocusaurusContext from '@docusaurus/useDocusaurusContext';
|
||||
import useIsBrowser from '@docusaurus/useIsBrowser';
|
||||
import {createStorageSlot} from './storageUtils';
|
||||
import {useThemeConfig} from './useThemeConfig';
|
||||
|
||||
|
@ -39,10 +39,10 @@ type AnnouncementBarAPI = {
|
|||
|
||||
const useAnnouncementBarContextValue = (): AnnouncementBarAPI => {
|
||||
const {announcementBar} = useThemeConfig();
|
||||
const {isClient} = useDocusaurusContext();
|
||||
const isBrowser = useIsBrowser();
|
||||
|
||||
const [isClosed, setClosed] = useState(() => {
|
||||
return isClient
|
||||
return isBrowser
|
||||
? // On client navigation: init with localstorage value
|
||||
isDismissedInStorage()
|
||||
: // On server/hydration: always visible to prevent layout shifts (will be hidden with css if needed)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue