Skip to content

Commit 10f3901

Browse files
committed
Update jsx3 migration guide
1 parent 74863e4 commit 10f3901

1 file changed

Lines changed: 89 additions & 95 deletions

File tree

‎website/docs/migration/jsx3.md‎

Lines changed: 89 additions & 95 deletions
Original file line numberDiff line numberDiff line change
@@ -18,58 +18,30 @@ coupled with our compatibility layer `bs-react-native-jsx3-compat`
1818
So first,
1919

2020
- be sure that you use `bs-platform@^5.0.1`
21-
- be sure to use `reason-react` master branch (until 0.7.1 or 0.8 is out) (at
22-
least commit
23-
[835b90c](https://github.com/reasonml/reason-react/commit/835b90c1c73827632a9819a353a404380724b1d2))
21+
- ⚠️ be sure to use
22+
`"reason-react": "https://github.com/reasonml/reason-react.git#835b90c"`
23+
(until 0.7.1 or 0.8 is out)
2424
- use `react@^16.8.0`
2525
- add `reason-react-compat@^0.4.0`
2626
- (if needed, upgrade some deps (eg: `reason-apollo@^0.16.0`))
27-
- use https://github.com/bloodyowl/upgrade-reason-react
28-
- **⚠ Note that if you use `->` operator a lot inside jsx, you will have a lot
29-
of bad surpise atm. We are working on improving the script.** Be warned.
30-
- if things breaks hard with `❗️️Errored on {somefile}`, that probably
31-
because something doesn't please the inlined version of refmt that's in the
32-
upgrade script. Things like this
33-
```reason
34-
StyleSheet.create(
35-
Style.{
36-
```
37-
will need to be replaced with
38-
```reason
39-
Style.(StyleSheet.create({
40-
```
41-
This also require you to adjust the other side of this StyleSheet declaration,
42-
so replace
43-
```reason
44-
},
45-
);
46-
```
47-
with
48-
```reason
49-
},
50-
));
51-
```
52-
Same for very short declarations
53-
```reason
54-
StyleSheet.create(Style.{
55-
```
56-
will need to be replaced with
57-
```reason
58-
Style.(StyleSheet.create({
59-
```
60-
And don't forget on the other side... `});` with `}));` Same apply for similar
61-
patterns...
27+
- use https://github.com/bloodyowl/upgrade-reason-react-esy
28+
29+
---
6230

6331
### Workaround for git usage
6432

65-
- `yarn add https://github.com/reasonml-community/reason-react-native.git#jsx3-migration`
33+
_If you use released packages, you can skip these steps._
34+
35+
- `yarn add https://github.com/reasonml-community/reason-react-native.git`
6636
- run a dirty command to get proper setup when using
6737
`bs-react-native-jsx3-compat`: add as a `prepare` script
6838
- `"prepare": "ln -sFf ../node_modules/reason-react-native-monorepo/reason-react-native/ ./node_modules",`
6939
- run `yarn prepare` (this will be run each time you use yarn & will ensure that
7040
the trick is always around until you actually use released versions of this
7141
work)
7242

43+
---
44+
7345
Now you can try to compile your code but it's unecessarry. **You might have tons
7446
of error because `bs-react-native` is full of jsx2** & we just migrated codebase
7547
to jsx3.
@@ -78,21 +50,21 @@ So please:
7850

7951
- Ensure your project is full jsx3 (`bsconfig.json`:
8052
`"reason": {"react-jsx": 3},`)
81-
- Replace `bs-react-native` by `reason-react-native-monorepo/bs-react-native-jsx3`
82-
in your `bsconfig.json` (**⚠️ check the
83-
[git monorepo trick](https://github.com/reasonml-community/reason-react-native#-usage-from-git-repo)**)
53+
- Replace `bs-react-native` by `bs-react-native-jsx3` in your `bsconfig.json`
54+
(or `reason-react-native-monorepo/bs-react-native-jsx3` for git users, check
55+
the
56+
[git monorepo trick](https://github.com/reasonml-community/reason-react-native#-usage-from-git-repo)
57+
if necessary)
58+
59+
🎉 **Compilation time!**
8460

85-
Compilation time! You should still have some errors, but probably not that much.
61+
You should still have some errors, but probably not that much.
8662

8763
## Time to fix remaining errors before everything works™
8864

8965
We did our best here to avoid you having to update/fix your code but there might
9066
still be some minor stuff to adjust
9167

92-
- you might find some weird error related to fast-pipe swapping code, this can
93-
be related to refmt issues, you will have to fix those by hand
94-
- eg: `{string_of_int(value)->ReasonReact.string}` turned into
95-
`{string_of_int;value->ReasonReact.string}`
9668
- check `children` errors and remove
9769
`let children = React.Children.toArray(children);` that might have beed added
9870
without being necessary
@@ -102,9 +74,9 @@ still be some minor stuff to adjust
10274

10375
### Notes about `ReasonReact.wrapJsForReason` & `ReasonReact.wrapReasonForJs`
10476

105-
With reason-react 0.7 & new api, code produced is just normal react component.
106-
So this things are not necessary anymore but are not handled by the script we
107-
used.
77+
With reason-react 0.7 & new api, JavaScript code produced is just normal React
78+
code. So this things are not necessary anymore but are not handled by the script
79+
we used.
10880

10981
So you might need to remove those things & replace them with vanilla React code
11082

@@ -120,7 +92,7 @@ So you might need to remove those things & replace them with vanilla React code
12092
When you don't have any errors, just compile & enjoy jsx3. You can even add
12193
`reason-react-native` to your `bsconfig.json` `bs-dependencies` & use it right
12294
away with
123-
[awesome hooks](https://reasonml.github.io/reason-react/docs/en/components) 🥳
95+
[awesome hooks](https://reasonml.github.io/reason-react/docs/en/components) !
12496

12597
Here are some commits that might help you
12698

@@ -129,17 +101,17 @@ Here are some commits that might help you
129101

130102
🙏 _Please do not hesitate to share your experience with the migration._ If the
131103
source is open, post your commit here, it could help someone without you even
132-
knowing 🤷‍♂️
104+
knowing 🤷‍
133105

134-
## Need help to migrate?
106+
## Need help to migrate ?
135107

136108
If you struggle with it & have questions,
137109
[reach us on our discord server](https://discord.gg/eaU3Z6Q)
138110

139111
---
140112

141-
**If you are reading this, you can assume you are done & ready to work on other
142-
things, like feature & bugfix for your product.**
113+
🎉 **If you are reading this, you can assume you are done & ready to work on
114+
other things, like feature & bugfix for your product.**
143115

144116
---
145117

@@ -148,47 +120,69 @@ things, like feature & bugfix for your product.**
148120
You can do some easy stuff to cleanup your codebase now that everything is
149121
working and that you are ready to use reason-react 0.7:
150122

151-
- Easy replacement
152-
- `ReasonReact.string` => `React.string`
153-
- `ReasonReact.array` => `React.array`
154-
- `ReasonReact.null` => `React.null`
155-
- `ReasonReact.reactElement` => `React.element`
156-
- ...
157-
- More tricky ones: you can probably remove lot of unecessary wrapping for
158-
stateless component that don't use the lifecycle
159-
```reason
160-
ReactCompat.useRecordApi({
161-
...component,
162-
render: _self => {
163-
```
164-
Can be replaced with
165-
```reason
166-
({{
167-
```
168-
And
169-
```reason
170-
ReactCompat.useRecordApi({
171-
...component,
172-
render: _self =>
173-
```
174-
Can be replaced with
175-
```reason
176-
({
177-
```
178-
At this point, the 2 replacements above have generated syntax error, so you
179-
should try to replace
180-
```reason
181-
,
182-
});
183-
```
184-
with
185-
```reason
123+
### Easy replacement
124+
125+
- `ReasonReact.string` => `React.string`
126+
- `ReasonReact.array` => `React.array`
127+
- `ReasonReact.null` => `React.null`
128+
- `ReasonReact.reactElement` => `React.element`
129+
- ...
130+
131+
### More tricky ones
132+
133+
You can probably remove lot of unecessary wrapping for stateless component that
134+
don't use the lifecycle
135+
136+
```reason
137+
ReactCompat.useRecordApi({
138+
...component,
139+
render: _self => {
140+
```
141+
142+
Can be replaced with
143+
144+
```reason
145+
({{
146+
147+
```
148+
149+
And
150+
151+
```reason
152+
ReactCompat.useRecordApi({
153+
...component,
154+
render: _self =>
155+
```
156+
157+
Can be replaced with
158+
159+
```reason
160+
({
161+
```
162+
163+
At this point, the 2 replacements above have generated syntax error, so you
164+
should try to replace
165+
166+
```reason
167+
,
186168
});
187-
```
188-
At this point, you should be able to drop some
189-
`let component = ReasonReact.statelessComponent...` too, since some won't be
190-
used anymore thanks to the last removal step we did.
169+
```
170+
171+
with
172+
173+
```reason
174+
});
175+
176+
```
177+
178+
At this point, you should be able to drop some
179+
`let component = ReasonReact.statelessComponent...` too, since some won't be
180+
used anymore thanks to the last removal step we did.
191181

192182
Now rely on refmt to get a cleaner code and you are good to go!
193183

194-
Do not hesitate to share more tips & tricks to ease the migration! Don't be shy!
184+
---
185+
186+
Do not hesitate to share more tips & tricks to ease the migration!
187+
188+
[Don't be shy!](https://github.com/reasonml-community/reason-react-native/issues/new?title=JSX3+migration+trick&body=Hey%20I%20have%20a%20trick%20that%20I%20can%20share%20with%20you%20to%20ease%20jsx3%20migration%3A)

0 commit comments

Comments
 (0)