You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: pages/docs/react/latest/beyond-jsx.mdx
+1-1
Original file line number
Diff line number
Diff line change
@@ -14,7 +14,7 @@ JSX is a syntax sugar that allows us to use React components in an HTML like man
14
14
15
15
**Note:** This section requires knowledge about the low level apis for [creating elements](./elements-and-jsx#creating-elements-from-component-functions), such as `React.createElement` or `ReactDOM.createDOMElementVariadic`.
16
16
17
-
> **Note:**This page assumes your `rescript.json` to be set to `"jsx": { "version": 4 }` to apply the right JSX transformations.
17
+
> **Note:**The output shown for the examples on this page assumes your `rescript.json` to be set to `"jsx": { "version": 4, "mode": "classic" }`. We will update it for automatic mode soon.
Copy file name to clipboardExpand all lines: pages/docs/react/latest/elements-and-jsx.mdx
+1-1
Original file line number
Diff line number
Diff line change
@@ -12,7 +12,7 @@ Elements are the smallest building blocks of React apps. This page will explain
12
12
13
13
</Intro>
14
14
15
-
> **Note:**This page assumes your `rescript.json` to be set to `"jsx": { "version": 4 }`, otherwise your JSX will not be transformed to its React specific form.
15
+
> **Note:**The output shown for the examples on this page assumes your `rescript.json` to be set to `"jsx": { "version": 4, "mode": "classic" }`. We will update it for automatic mode soon.
> **Note:**This page assumes your `rescript.json` to be set to `"jsx": { "version": 4 }` to apply the right JSX transformations.
9
+
> **Note:**The output shown for the examples on this page assumes your `rescript.json` to be set to `"jsx": { "version": 4, "mode": "classic" }`. We will update it for automatic mode soon.
Add following dependency to your ReScript project (in case you don't have any project yet, check out the [installation instructions](/docs/manual/latest/installation) in the manual):
14
+
Add the following dependency to your ReScript project (in case you don't have any project yet, check out the [installation instructions](/docs/manual/latest/installation)):
15
15
16
16
```
17
17
npm install @rescript/react
@@ -21,14 +21,12 @@ Then add the following setting to your existing `rescript.json`:
21
21
22
22
```json
23
23
{
24
-
"jsx": { "version": 4, "mode": "classic" },
24
+
"jsx": { "version": 4 },
25
25
"bs-dependencies": ["@rescript/react"]
26
26
}
27
27
```
28
28
29
-
> The [new jsx transform](https://ko.reactjs.org/blog/2020/09/22/introducing-the-new-jsx-transform.html) of ReactJS is available with `mode: "automatic"`.
30
-
31
-
**Note** JSX v4 is newly introduced with the idiomatic record-based representation of a component. If your dependencies are not compatible with v4 yet, then you can use v3 in the same project. Check out the details in [Migrate from v3](/docs/react/latest/migrate-react)
29
+
**Note:** In case your dependencies are not compatible with version 4 of the ReScript JSX transformation yet, you can use v3 in the same project. Check out the details in [Migrate from v3](/docs/react/latest/migrate-react).
32
30
33
31
To test your setup, create a new `.res` file in your source directory and add the following code:
34
32
@@ -53,3 +51,21 @@ After a successful installation, `@rescript/react` will make the following modul
53
51
-`ReactDOMStyle`: Bindings to the inline style API
54
52
-`RescriptReactRouter`: A simple, yet fully featured router with minimal memory allocations
55
53
-`RescriptReactErrorBoundary`: A component which handles errors thrown in its child components gracefully
54
+
55
+
## Automatic vs. Classic Mode
56
+
57
+
By default, JSX v4 uses the new JSX runtime (`react/jsx-runtime`) introduced in React 17. This is called "automatic mode", and can also be specified explicitly like this:
58
+
59
+
```json
60
+
{
61
+
"jsx": { "version": 4, "mode": "automatic" }
62
+
}
63
+
```
64
+
65
+
To keep using the legacy `React.createElement` API (like with JSX v3), you can activate classic mode instead:
ReScript offers first class bindings for [ReactJS](https://reactjs.org) and is designed and built by people using ReScript and React in large mission critical React codebases. The bindings are compatible with modern React versions (>= v18.0).
9
+
ReScript offers first class bindings for [ReactJS](https://react.dev) and is designed and built by people using ReScript and React in large mission critical React codebases. The bindings are compatible with modern React versions (>= v18.0).
10
10
11
11
The ReScript philosophy is to compile as closely to idiomatic JS code as possible; in the case of ReactJS, we made no exception, so it's not only easy to transfer all the React knowledge to the ReScript platform, but also straightforward to integrate with existing ReactJS codebases and libraries.
12
12
@@ -22,7 +22,7 @@ All our documented examples can be compiled in our [ReScript Playground](/try) a
22
22
23
23
> **This documentation assumes basic knowledge about ReactJS.**
24
24
>
25
-
> Please note that even though we will cover many basic React concepts, it might still be necessary to have a look at the official [ReactJS](https://reactjs.org) resources, especially if you are a complete beginner with React.
25
+
> Please note that even though we will cover many basic React concepts, it might still be necessary to have a look at the official [ReactJS](https://react.dev) resources, especially if you are a complete beginner with React.
JSX v4 introduces a new idiomatic record-based representation of components which is incompatible with v3. Because of this, either the entire project or dependencies need to be compiled in V4 mode, or some compatibility features need to be used to mix V3 and V4 in the same project. This page describes how to migrate from v3 to v4.
9
+
JSX v4 introduces a new idiomatic record-based representation of components which is incompatible with v3. Because of this, either the entire project or dependencies need to be compiled in v4 mode, or some compatibility features need to be used to mix v3 and v4 in the same project. This page describes how to migrate from v3 to v4.
10
10
11
11
## Configuration
12
12
@@ -26,25 +26,14 @@ Then add the new JSX configuration:
26
26
}
27
27
```
28
28
29
-
**Note** JSX v4 requires the rescript compiler 10.1 or higher, and rescript-react version 0.11 or higher. In addition, react version 18.0 is required.
30
-
31
-
### Classic and Automatic Mode
32
-
33
-
Classic mode is the default and generates calls to `React.createElement` just as with V3.
29
+
or, to keep using the legacy `React.createElement` API like with JSX v3:
34
30
35
31
```json
36
32
{
37
33
"jsx": { "version": 4, "mode": "classic" }
38
34
}
39
35
```
40
36
41
-
Automatic mode is an experimental mode that generate calls to `_jsx` functions (similar to TypeScript's `react-jsx` mode)
42
-
43
-
```json
44
-
{
45
-
"jsx": { "version": 4, "mode": "automatic" }
46
-
}
47
-
```
48
37
49
38
### File-level config
50
39
@@ -84,9 +73,9 @@ JSX v3 is still available with the latest version of compiler and rescript-react
84
73
}
85
74
```
86
75
87
-
To build certain dependencies in V3 compatibility mode, whatever the version used in the root project, use `"v3-dependencies"`. The listed dependencies will be built in V3 mode, and in addition `-open ReactV3` is added to the compiler options.
76
+
To build certain dependencies in v3 compatibility mode, whatever the version used in the root project, use `"v3-dependencies"`. The listed dependencies will be built in v3 mode, and in addition `-open ReactV3` is added to the compiler options.
88
77
89
-
## Migration of V3 components
78
+
## Migration of v3 components
90
79
91
80
Some components in existing projects are written in a way that is dependent on the v3 internal representation. Here are a few examples of how to convert them to v4.
92
81
@@ -179,7 +168,7 @@ let make = () => {
179
168
}
180
169
```
181
170
182
-
To this: In v3, there is an inconsistency between `ref` as prop and `ref_` as argument. With JSX V4, `ref` is only allowed as an argument.
171
+
To this: In v3, there is an inconsistency between `ref` as prop and `ref_` as argument. With JSX v4, `ref` is only allowed as an argument.
0 commit comments