mirror of
https://github.com/facebook/docusaurus.git
synced 2025-07-29 06:29:03 +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 ExecutionEnvironment from './ExecutionEnvironment';
|
||||
import useDocusaurusContext from '@docusaurus/useDocusaurusContext';
|
||||
|
||||
function BrowserOnly({
|
||||
children,
|
||||
|
@ -15,11 +15,13 @@ function BrowserOnly({
|
|||
children?: () => JSX.Element;
|
||||
fallback?: JSX.Element;
|
||||
}): JSX.Element | null {
|
||||
if (!ExecutionEnvironment.canUseDOM || children == null) {
|
||||
return fallback || null;
|
||||
const {isClient} = useDocusaurusContext();
|
||||
|
||||
if (isClient && children != null) {
|
||||
return <>{children()}</>;
|
||||
}
|
||||
|
||||
return <>{children()}</>;
|
||||
return fallback || null;
|
||||
}
|
||||
|
||||
export default BrowserOnly;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue