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:
Sébastien Lorber 2021-08-12 19:02:29 +02:00 committed by GitHub
parent 69b11a8546
commit 295e77cc09
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
20 changed files with 213 additions and 90 deletions

View file

@ -8,14 +8,14 @@
import React from 'react';
import clsx from 'clsx';
import useDocusaurusContext from '@docusaurus/useDocusaurusContext';
import useIsBrowser from '@docusaurus/useIsBrowser';
import useThemeContext from '@theme/hooks/useThemeContext';
import type {Props} from '@theme/ThemedImage';
import styles from './styles.module.css';
const ThemedImage = (props: Props): JSX.Element => {
const {isClient} = useDocusaurusContext();
const isBrowser = useIsBrowser();
const {isDarkTheme} = useThemeContext();
const {sources, className, alt = '', ...propsRest} = props;
@ -23,7 +23,7 @@ const ThemedImage = (props: Props): JSX.Element => {
const clientThemes: SourceName[] = isDarkTheme ? ['dark'] : ['light'];
const renderedSourceNames: SourceName[] = isClient
const renderedSourceNames: SourceName[] = isBrowser
? clientThemes
: // We need to render both images on the server to avoid flash
// See https://github.com/facebook/docusaurus/pull/3730