| slug | install |
|---|---|
| title | Installation |
Depending on how you want to start with ReScript React Native, you have different options:
All options will basically help you to have:
- ReScript (
rescriptβ₯ 12) - ReScript React (
@rescript/reactβ₯ 0.15) - ReScript React Native (
rescript-react-nativeβ₯ 0.84) - React Native (
react-nativeβ₯ 0.84)
Below we assume you are already familiar with React Native. If you are new to React Native, please have a quick look at the React Native environment setup guide in order to get the minimal requirements.
React Native allows creating a new project from a template, so we made one. By choosing this option you will get a hello world project that already includes all the requirements.
Requirements:
- Node.js β₯ 22.11
- A working React Native environment
npx @react-native-community/cli@latest init MyApp --template @rescript-react-native/template
cd MyAppThen run the ReScript watcher alongside Metro:
npm run res:watch
npm startπ Your project is set up β you can check how to use ReScript React Native right away!
If you are an Expo user, just have a look at the instructions below when your Expo app is ready.
If you already have an existing React Native 0.84+ project, it's quick to add ReScript React Native.
π You can decide to use ReScript React Native for certain components only as the compilation process generates normal JavaScript.
Go into your project root & then install the requirements:
npm install rescript@^12 @rescript/react@^0.15 rescript-react-native@^0.84Then create a file named rescript.json at the same level as your
package.json with the following content:
{
"name": "my-rescript-react-native-app",
"jsx": {
"version": 4
},
"package-specs": {
"module": "esmodule",
"in-source": true
},
"suffix": ".res.js",
"sources": [
{
"dir": "src",
"subdirs": true
}
],
"dependencies": ["@rescript/react", "rescript-react-native"]
}You will also want scripts in package.json:
{
"scripts": {
"res:clean": "rescript clean",
"res:build": "rescript",
"res:watch": "rescript build -w",
"prepare": "rescript"
}
}The main things you should notice here:
- JavaScript generated will use ES modules (
import/export). - JavaScript generated files will have a
.res.jsextension. - ReScript code will be compiled from the
srcfolder. - ReScript will use
@rescript/react&rescript-react-nativeas dependencies.
π For details about this file, please refer to ReScript Configuration documentation if needed.
When it's done, you are ready to use ReScript React Native!
We decided to try something simple for you:
βοΈ rescript-react-native 0.84.* means it should work with react-native
^0.84.0.
We keep the patch number for bindings fixes. react-native patches should not
affect our bindings. This means the last digit doesn't need to match:
react-native@0.84.1should work withrescript-react-native@0.84.0react-native@0.84.0should work withrescript-react-native@0.84.0
π In short: rescript-react-native 0.x.* means it should work with
react-native@^0.x.*.
Current peer dependencies for 0.84:
react-nativeβ₯0.84.0rescriptβ₯12.0.0@rescript/reactβ₯0.15.0