Hook up components

This commit is contained in:
Dan Abramov
2024-07-06 06:18:32 +01:00
parent 0c4cae0148
commit ec9db8470d
4 changed files with 30 additions and 10 deletions
+6 -4
View File
@@ -53,13 +53,15 @@ async function renderApp(res, returnValue, formState) {
// const m = require('../src/App.js');
const m = await import('../src/App.js')
const moduleMap = {
Text: {
id: 'Text',
let moduleMap = {}
for (let id of Object.keys(await import('../src/client.js'))) {
moduleMap[id] = {
id,
name: 'default',
chunks: ['main'],
},
}
}
const App = m.default.default || m.default
const root = React.createElement(
React.Fragment,
+6 -2
View File
@@ -1,9 +1,13 @@
import * as React from 'react'
import {Text} from './client.js'
import {Label, Stack} from './client.js'
export default async function App() {
return <Text>hello</Text>
return (
<Stack gap={10}>
<Label size={36} lineHeight={1.2} weight="bold" text="Hello, world!" />
</Stack>
)
}
// TODO
+15 -3
View File
@@ -1,4 +1,16 @@
export const Text = {
$$typeof: Symbol.for('react.client.reference'),
$$id: 'Text',
export const Text = createClientReference('Text')
export const ActorLabel = createClientReference('ActorLabel')
export const Avatar = createClientReference('Avatar')
export const Box = createClientReference('Box')
export const Embed = createClientReference('Embed')
export const Expandable = createClientReference('Expandable')
export const Label = createClientReference('Label')
export const Stack = createClientReference('Stack')
export const Tabs = createClientReference('Tabs')
function createClientReference(id) {
return {
$$typeof: Symbol.for('react.client.reference'),
$$id: id,
}
}
+3 -1
View File
@@ -1,3 +1,4 @@
import React, {Suspense} from 'react'
import {useQuery} from '@tanstack/react-query'
// @ts-ignore
import {createFromFetch} from 'react-server-dom-webpack/client'
@@ -23,5 +24,6 @@ export function AppComponent({origin}: {origin: string}) {
if (!data) {
return null // TODO
}
return data.root
return <Suspense fallback={null /* TODO */}>{data.root}</Suspense>
}