Skip to content

Commit 8b8cfb9

Browse files
committed
Ensure sample compiles
1 parent 483f414 commit 8b8cfb9

File tree

1 file changed

+41
-4
lines changed

1 file changed

+41
-4
lines changed

pages/docs/react/latest/server-components.mdx

Lines changed: 41 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,13 +64,19 @@ let helloWorld: unit => Promise<string>
6464

6565
```res example
6666
// src/pages/Index.res
67+
let data = [1, 2, 3]
68+
let getData = () => Promise.resolve(data)
69+
6770
@react.component
6871
let make = async () => {
6972
// fetch some data from somewhere
7073
let data = await getData()
7174
<html>
7275
<body>
7376
<h1> {React.string("Hello from server component")} </h1>
77+
<ul>
78+
{data->Array.map(id => <li> {React.int(id)} </li>)->React.array}
79+
</ul>
7480
</body>
7581
</html>
7682
}
@@ -112,29 +118,55 @@ A server function can be inlined in a server component and passed as prop to a c
112118
<CodeTab labels={["ReScript", "JS Output"]}>
113119

114120
```res
121+
module ClientComp = {
122+
@react.component @module("some-module")
123+
external make: (~submit: int => promise<bool>) => React.element =
124+
"SomeClientComp"
125+
}
126+
127+
let data = [1, 2, 3]
128+
let getData = () => Promise.resolve(data)
129+
115130
@react.component
116131
let make = async () => {
117132
let data = await getData()
118133
119134
let addData =
120135
@directive("'use server'")
121-
async (name: string) => {
136+
async (id: int) => {
122137
// add to data store
138+
data->Array.push(id)
123139
true
124140
}
125141
<html>
126142
<body>
127143
<h1> {React.string("Hello from server component")} </h1>
144+
<ul>
145+
{data->Array.map(id => <li> {React.int(id)} </li>)->React.array}
146+
</ul>
128147
<ClientComp submit={addData} />
129148
</body>
130149
</html>
131150
}
132151
```
133152
```js
153+
import * as SomeModule from "some-module";
154+
155+
let data = [
156+
1,
157+
2,
158+
3
159+
];
160+
161+
function getData() {
162+
return Promise.resolve(data);
163+
}
164+
134165
async function make(param) {
135-
await getData();
136-
let addData = async name => {
166+
let data$1 = await Promise.resolve(data);
167+
let addData = async id => {
137168
'use server';
169+
data$1.push(id);
138170
return true;
139171
};
140172
return JsxRuntime.jsx("html", {
@@ -143,7 +175,12 @@ async function make(param) {
143175
JsxRuntime.jsx("h1", {
144176
children: "Hello from server component"
145177
}),
146-
JsxRuntime.jsx(ClientComp, {
178+
JsxRuntime.jsx("ul", {
179+
children: data$1.map(id => JsxRuntime.jsx("li", {
180+
children: id
181+
}))
182+
}),
183+
JsxRuntime.jsx(SomeModule.SomeClientComp, {
147184
submit: addData
148185
})
149186
]

0 commit comments

Comments
 (0)