mirror of
https://github.com/facebook/docusaurus.git
synced 2025-07-30 23:08:54 +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
|
@ -10,6 +10,7 @@ import {LiveProvider, LiveEditor, LiveError, LivePreview} from 'react-live';
|
|||
import clsx from 'clsx';
|
||||
import Translate from '@docusaurus/Translate';
|
||||
import useDocusaurusContext from '@docusaurus/useDocusaurusContext';
|
||||
import useIsBrowser from '@docusaurus/useIsBrowser';
|
||||
import usePrismTheme from '@theme/hooks/usePrismTheme';
|
||||
import styles from './styles.module.css';
|
||||
|
||||
|
@ -51,8 +52,8 @@ function EditorWithHeader() {
|
|||
}
|
||||
|
||||
export default function Playground({children, transformCode, ...props}) {
|
||||
const isBrowser = useIsBrowser();
|
||||
const {
|
||||
isClient,
|
||||
siteConfig: {
|
||||
themeConfig: {
|
||||
liveCodeBlock: {playgroundPosition},
|
||||
|
@ -64,8 +65,8 @@ export default function Playground({children, transformCode, ...props}) {
|
|||
return (
|
||||
<div className={styles.playgroundContainer}>
|
||||
<LiveProvider
|
||||
key={isClient}
|
||||
code={isClient ? children.replace(/\n$/, '') : ''}
|
||||
key={isBrowser}
|
||||
code={isBrowser ? children.replace(/\n$/, '') : ''}
|
||||
transformCode={transformCode || ((code) => `${code};`)}
|
||||
theme={prismTheme}
|
||||
{...props}>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue