/** * Copyright (c) Meta Platforms, Inc. and affiliates. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * * @flow */ import * as React from 'react'; function deferred( timeoutMS: number, resolvedValue: T, displayName: string, ): Promise { const promise = new Promise(resolve => { setTimeout(() => resolve(resolvedValue), timeoutMS); }); (promise as any).displayName = displayName; return promise; } const title = deferred(100, 'Segmented Page Title', 'title'); const content = deferred( 400, 'This is the content of a segmented page. It loads in multiple parts.', 'content', ); function Page(): React.Node { return (

{title}

{content}

); } function InnerSegment({children}: {children: React.Node}): React.Node { return ( <>

Inner Segment

Loading...

}>
{children}

After inner

); } const cookies = deferred(200, 'Cookies: 🍪🍪🍪', 'cookies'); function OuterSegment({children}: {children: React.Node}): React.Node { return ( <>

Outer Segment

Loading outer

}>

{cookies}

{children}

After outer

); } function Root({children}: {children: React.Node}): React.Node { return ( <>

Root Segment

Loading root

}>
{children}
After root
); } const dynamicData = deferred(10, 'Dynamic Data: 📈📉📊', 'dynamicData'); export default function Segments(): React.Node { return ( <>

{dynamicData}

); }