// @flow import React, { Suspense, useState } from 'react'; function SuspenseTree() { return ( <>

Suspense

Primary to Fallback Cycle

Fallback to Primary Cycle

); } function PrimaryFallbackTest({ initialSuspend }) { const [suspend, setSuspend] = useState(initialSuspend); const fallbackStep = useTestSequence('fallback', Fallback1, Fallback2); const primaryStep = useTestSequence('primary', Primary1, Primary2); return ( <>
{suspend ? : primaryStep} ); } function useTestSequence(label, T1, T2) { let [step, setStep] = useState(0); let next = ( ); let allSteps = [ <>{next}, <> {next} mount , <> {next} update , <> {next} several different{' '} children , <> {next} goodbye , ]; return allSteps[step]; } function NestedSuspenseTest() { return ( <>

Nested Suspense

Loading outer}> ); } function Parent() { return (
Loading inner 1}> Hello {' '} Loading inner 2}> World
This will never load}>
); } function LoadLater() { const [loadChild, setLoadChild] = useState(0); return ( setLoadChild(true)}>Click to load } > {loadChild ? ( setLoadChild(false)}> Loaded! Click to suspend again. ) : ( )} ); } function Never() { throw new Promise(resolve => {}); } function Fallback1({ prop, ...rest }) { return ; } function Fallback2({ prop, ...rest }) { return ; } function Primary1({ prop, ...rest }) { return ; } function Primary2({ prop, ...rest }) { return ; } export default SuspenseTree;