Skip to content

Commit 6d567e3

Browse files
React 18 (rescript-lang#46)
* React 18 support * Fix module typo * Uncurried useTransition * Add ReactDOM.Client * Fix build errors * Address PR feedback * Fix instances of useTransition Co-authored-by: Tom Sherman <the.tomsherman@gmail.com>
1 parent 7aef751 commit 6d567e3

File tree

5 files changed

+76
-23
lines changed

5 files changed

+76
-23
lines changed

src/React.res

+54-8
Original file line numberDiff line numberDiff line change
@@ -367,6 +367,60 @@ external useImperativeHandle7: (
367367
('a, 'b, 'c, 'd, 'e, 'f, 'g),
368368
) => unit = "useImperativeHandle"
369369

370+
@module("react") external useId: unit => string = "useId"
371+
372+
@module("react") external useDeferredValue: 'value => 'value = "useDeferredValue"
373+
374+
@module("react")
375+
external useTransition: unit => (bool, (. unit => unit) => unit) = "useTransition"
376+
377+
@module("react")
378+
external useInsertionEffect: (@uncurry (unit => option<unit => unit>)) => unit =
379+
"useInsertionEffect"
380+
@module("react")
381+
external useInsertionEffect0: (@uncurry (unit => option<unit => unit>), @as(json`[]`) _) => unit =
382+
"useInsertionEffect"
383+
@module("react")
384+
external useInsertionEffect1: (@uncurry (unit => option<unit => unit>), array<'a>) => unit =
385+
"useInsertionEffect"
386+
@module("react")
387+
external useInsertionEffect2: (@uncurry (unit => option<unit => unit>), ('a, 'b)) => unit =
388+
"useInsertionEffect"
389+
@module("react")
390+
external useInsertionEffect3: (@uncurry (unit => option<unit => unit>), ('a, 'b, 'c)) => unit =
391+
"useInsertionEffect"
392+
@module("react")
393+
external useInsertionEffect4: (@uncurry (unit => option<unit => unit>), ('a, 'b, 'c, 'd)) => unit =
394+
"useInsertionEffect"
395+
@module("react")
396+
external useInsertionEffect5: (
397+
@uncurry (unit => option<unit => unit>),
398+
('a, 'b, 'c, 'd, 'e),
399+
) => unit = "useInsertionEffect"
400+
@module("react")
401+
external useInsertionEffect6: (
402+
@uncurry (unit => option<unit => unit>),
403+
('a, 'b, 'c, 'd, 'e, 'f),
404+
) => unit = "useInsertionEffect"
405+
@module("react")
406+
external useInsertionEffect7: (
407+
@uncurry (unit => option<unit => unit>),
408+
('a, 'b, 'c, 'd, 'e, 'f, 'g),
409+
) => unit = "useInsertionEffect"
410+
411+
@module("react")
412+
external useSyncExternalStore: (
413+
~subscribe: @uncurry ((unit => unit) => ((. unit) => unit)),
414+
~getSnapshot: @uncurry unit => 'state,
415+
) => 'state = "useSyncExternalStore"
416+
417+
@module("react")
418+
external useSyncExternalStoreWithServerSnapshot: (
419+
~subscribe: @uncurry ((unit => unit) => ((. unit) => unit)),
420+
~getSnapshot: @uncurry unit => 'state,
421+
~getServerSnapshot: @uncurry unit => 'state,
422+
) => 'state = "useSyncExternalStore"
423+
370424
module Uncurried = {
371425
@module("react")
372426
external useState: (@uncurry (unit => 'state)) => ('state, (. 'state => 'state) => unit) =
@@ -433,14 +487,6 @@ module Uncurried = {
433487
) => callback<'input, 'output> = "useCallback"
434488
}
435489

436-
type transitionConfig = {timeoutMs: int}
437-
438-
@module("react")
439-
external useTransition: (
440-
~config: transitionConfig=?,
441-
unit,
442-
) => (callback<callback<unit, unit>, unit>, bool) = "useTransition"
443-
444490
@set
445491
external setDisplayName: (component<'props>, string) => unit = "displayName"
446492

src/ReactDOM.bs.js

+6-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/ReactDOM.res

+14-6
Original file line numberDiff line numberDiff line change
@@ -10,27 +10,35 @@
1010
external querySelector: string => option<Dom.element> = "document.querySelector"
1111

1212
@module("react-dom")
13+
@deprecated("ReactDOM.render is no longer supported in React 18. Use ReactDOM.Client.createRoot instead.")
1314
external render: (React.element, Dom.element) => unit = "render"
1415

15-
module Experimental = {
16-
type root
16+
module Client = {
1717

18-
@module("react-dom/client")
19-
external createRoot: Dom.element => root = "createRoot"
18+
module Root = {
19+
type t
20+
21+
@send external render: (t, React.element) => unit = "render"
22+
23+
@send external unmount: (t, unit) => unit = "unmount"
24+
}
2025

2126
@module("react-dom/client")
22-
external createBlockingRoot: Dom.element => root = "createBlockingRoot"
27+
external createRoot: Dom.element => Root.t = "createRoot"
2328

24-
@send external render: (root, React.element) => unit = "render"
29+
@module("react-dom/client")
30+
external hydrateRoot: (Dom.element, React.element) => Root.t = "hydrateRoot"
2531
}
2632

2733
@module("react-dom")
34+
@deprecated("ReactDOM.hydrate is no longer supported in React 18. Use ReactDOM.Client.hydrateRoot instead.")
2835
external hydrate: (React.element, Dom.element) => unit = "hydrate"
2936

3037
@module("react-dom")
3138
external createPortal: (React.element, Dom.element) => React.element = "createPortal"
3239

3340
@module("react-dom")
41+
@deprecated("ReactDOM.unmountComponentAtNode is no longer supported in React 18. Use ReactDOM.Client.Root.unmount instead.")
3442
external unmountComponentAtNode: Dom.element => unit = "unmountComponentAtNode"
3543

3644
external domElementToObj: Dom.element => {..} = "%identity"

src/v3/ReactDOM_V3.res

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ external querySelector: string => option<Dom.element> = "document.querySelector"
1313
external render: (React.element, Dom.element) => unit = "render"
1414

1515
module Experimental = {
16-
type root = ReactDOM.Experimental.root
16+
type root = ReactDOM.Client.Root.t
1717

1818
@module("react-dom")
1919
external createRoot: Dom.element => root = "createRoot"

src/v3/React_V3.res

+1-6
Original file line numberDiff line numberDiff line change
@@ -437,13 +437,8 @@ module Uncurried = {
437437
) => callback<'input, 'output> = "useCallback"
438438
}
439439

440-
type transitionConfig = React.transitionConfig
441-
442440
@module("react")
443-
external useTransition: (
444-
~config: transitionConfig=?,
445-
unit,
446-
) => (callback<callback<unit, unit>, unit>, bool) = "useTransition"
441+
external useTransition: unit => (bool, (. unit => unit) => unit) = "useTransition"
447442

448443
@set
449444
external setDisplayName: (component<'props>, string) => unit = "displayName"

0 commit comments

Comments
 (0)