You are currently looking at the v0.12.0 docs, which are still a work in progress. If you miss anything, you may find it in the older v0.11.0 docs here.
Installation
Requirements:
rescript@10.1
or laterreact@18.0.0
or later
Add following dependency to your ReScript project (in case you don't have any project yet, check out the installation instructions in the manual):
npm install @rescript/react
Then add the following setting to your existing rescript.json
:
JSON{
"jsx": { "version": 4, "mode": "classic" },
"bs-dependencies": ["@rescript/react"]
}
The new jsx transform of ReactJS is available with
mode: "automatic"
.
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
To test your setup, create a new .res
file in your source directory and add the following code:
RES// src/Test.res
@react.component
let make = () => {
<div> {React.string("Hello World")} </div>
}
Now run npx rescript
and you should see a successful build.
Exposed Modules
After a successful installation, @rescript/react
will make the following modules available in your project's global scope:
React
: Bindings to ReactReactDOM
: Bindings to the ReactDOMReactDOMServer
: Bindings to the ReactDOMServerReactEvent
: Bindings to React's synthetic eventsReactDOMStyle
: Bindings to the inline style APIRescriptReactRouter
: A simple, yet fully featured router with minimal memory allocationsRescriptReactErrorBoundary
: A component which handles errors thrown in its child components gracefully