I want to pass a flag prop to Suspense component, telling it to behave like a normal div, hence being loaded immediately when renderToPipeableStream
on the server.
import React, { Suspense } from 'react';
function ConditionalSuspense(): React.ReactElement {
return (
<Suspense enabled={false}>
<div>
<div>When enabled is false, this will be loaded sync on server</div>
<Suspense>This will be loaded async on client, because by default suspense is enabled</Suspense>
</div>
</Suspense>
);
}
On the server I will have
import { renderToPipeableStream } from 'react-dom/server';
import { ConditionalSuspense } from './ui';
const stream = renderToPipeableStream(ConditionalSuspense, ...);