mirror of
https://github.com/facebook/docusaurus.git
synced 2025-07-29 22:47:52 +02:00
fix(v2): render children in BrowserOnly after client is ready (#4935)
* fix(v2): render children in BrowserOnly after client is ready * Fix fallback issue
This commit is contained in:
parent
869f4bf206
commit
d81d43c247
1 changed files with 6 additions and 4 deletions
|
@ -6,7 +6,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import ExecutionEnvironment from './ExecutionEnvironment';
|
import useDocusaurusContext from '@docusaurus/useDocusaurusContext';
|
||||||
|
|
||||||
function BrowserOnly({
|
function BrowserOnly({
|
||||||
children,
|
children,
|
||||||
|
@ -15,11 +15,13 @@ function BrowserOnly({
|
||||||
children?: () => JSX.Element;
|
children?: () => JSX.Element;
|
||||||
fallback?: JSX.Element;
|
fallback?: JSX.Element;
|
||||||
}): JSX.Element | null {
|
}): JSX.Element | null {
|
||||||
if (!ExecutionEnvironment.canUseDOM || children == null) {
|
const {isClient} = useDocusaurusContext();
|
||||||
return fallback || null;
|
|
||||||
|
if (isClient && children != null) {
|
||||||
|
return <>{children()}</>;
|
||||||
}
|
}
|
||||||
|
|
||||||
return <>{children()}</>;
|
return fallback || null;
|
||||||
}
|
}
|
||||||
|
|
||||||
export default BrowserOnly;
|
export default BrowserOnly;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue