Skip to content

Commit d082ac4

Browse files
committed
add automatic codes
1 parent 3671316 commit d082ac4

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

pages/docs/react/latest/beyond-jsx.mdx

+20-1
Original file line numberDiff line numberDiff line change
@@ -114,13 +114,17 @@ So now that we know how the ReScript React component transformation works, let's
114114

115115
Whenever we are using JSX with a custom component ("capitalized JSX"), we are actually using `React.createElement` to create a new element. Here is an example of a React component without children:
116116

117-
<CodeTab labels={["JSX", "Without JSX"]}>
117+
<CodeTab labels={["JSX", "Without JSX", "JS Output"]}>
118118

119119
```res
120120
<Friend name="Fred" age=20 />
121121
```
122122
```res
123+
// classic
123124
React.createElement(Friend.make, {name: "Fred", age:20})
125+
126+
// automatic
127+
React.jsx(Friend.make, {name: "Fred", age: 20})
124128
```
125129
```js
126130
React.createElement(Playground$Friend, { name: "Fred", age: 20 });
@@ -140,11 +144,18 @@ As you can see, it uses `Friend.make` to call the `React.createElement` API. In
140144
```
141145

142146
```res
147+
// classic
143148
React.createElementVariadic(
144149
Container.make,
145150
{width: 200, children: React.null},
146151
[{React.string("Hello")}, {React.string("World")}],
147152
)
153+
154+
// automatic
155+
React.jsxs(
156+
Container.make,
157+
{width: 200, children: React.array([{React.string("Hello")}, {React.string("World")}])},
158+
)
148159
```
149160

150161
```js
@@ -167,7 +178,11 @@ Note that the `children: React.null` field has no relevance since React will onl
167178
```
168179

169180
```res
181+
// classic
170182
ReactDOM.createDOMElementVariadic("div", ~props={title: "test"}, [])
183+
184+
// automatic
185+
ReactDOM.jsx("div", {title: "test"})
171186
```
172187

173188
```js
@@ -187,11 +202,15 @@ The same goes for uncapitalized JSX with children:
187202
```
188203

189204
```res
205+
// classic
190206
ReactDOM.createDOMElementVariadic(
191207
"div",
192208
~props={title: "test"},
193209
[ReactDOM.createDOMElementVariadic("span", [])],
194210
)
211+
212+
// automatic
213+
ReactDOM.jsx("div", {title: "test", children: ?ReactDOM.someElement(ReactDOM.jsx("span", {}))})
195214
```
196215

197216
```js

0 commit comments

Comments
 (0)