11/** @jsxRuntime automatic */
22/** @jsxImportSource react */
33
4- import { createRemoteComponent } from '@remote-dom/react' ;
5- import { createRoot } from 'react-dom/client' ;
4+ import { createRemoteComponent } from '@remote-dom/react' ;
5+ import { createRoot } from 'react-dom/client' ;
66
7- import type { RenderAPI } from '../../types.ts' ;
8- import { Stack as StackElement , Text as TextElement } from '../elements.ts' ;
9- import { useRenders } from './utils/react-hooks.ts' ;
7+ import { useEffect , useState } from 'react' ;
8+ import type { RenderAPI } from '../../types.ts' ;
9+ import { Stack as StackElement , Text as TextElement } from '../elements.ts' ;
10+ import { useRenders } from './utils/react-hooks.ts' ;
1011
1112const Stack = createRemoteComponent ( 'ui-stack' , StackElement ) ;
1213const Text = createRemoteComponent ( 'ui-text' , TextElement ) ;
@@ -48,6 +49,39 @@ const Example1 = () => {
4849} ;
4950
5051const Example2 = ( ) => {
52+ const [ loading , setLoading ] = useState ( true ) ;
53+
54+ useEffect ( ( ) => {
55+ setLoading ( false ) ;
56+ } , [ setLoading ] ) ;
57+
58+ return (
59+ < Stack spacing testId = "test-stack" >
60+ < >
61+ { loading && loading1 }
62+ { ! loading && (
63+ < >
64+ { data1 }
65+ { data2 }
66+ </ >
67+ ) }
68+ </ >
69+ < >
70+ { loading && loading2 }
71+ { ! loading && (
72+ < >
73+ { data3 }
74+ { data4 }
75+ </ >
76+ ) }
77+ </ >
78+ { ! loading && done }
79+ </ Stack >
80+ ) ;
81+ } ;
82+
83+
84+ const Example3 = ( ) => {
5185 const renders = useRenders ( 2 ) ;
5286
5387 return (
@@ -60,14 +94,17 @@ const Example2 = () => {
6094 ) ;
6195} ;
6296
97+
6398function App ( { api} : { api : RenderAPI } ) {
64- if ( api . example === 'react-mutations-1' ) {
65- return < Example1 /> ;
66- }
99+ const { example} = api ;
67100
68- if ( api . example === 'react-mutations-2' ) {
69- return < Example2 /> ;
70- }
101+ return example === 'react-mutations-1' ? (
102+ < Example1 />
103+ ) : example === 'react-mutations-2' ? (
104+ < Example2 />
105+ ) : example === 'react-mutations-3' ? (
106+ < Example3 />
107+ ) : null ;
71108}
72109
73110export function renderUsingReact ( root : Element , api : RenderAPI ) {
0 commit comments