-
-
Notifications
You must be signed in to change notification settings - Fork 137
/
version18.cljc
37 lines (35 loc) · 1.55 KB
/
version18.cljc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
(ns com.fulcrologic.fulcro.react.version18
#?@(:cljs
[(:require-macros com.fulcrologic.fulcro.react.version18)
(:require
[com.fulcrologic.fulcro.application]
["react-dom/client" :as dom-client]
["react" :as react])]))
(defn react18-options
"Returns the options that need to be passed to the Fulcro app constructor. See also `with-react18`."
[]
#?(:cljs
(let [reactRoot (volatile! nil)]
{:render-root! (fn [ui-root mount-node]
(when-not @reactRoot
(vreset! reactRoot (dom-client/createRoot mount-node)))
(.render ^js @reactRoot ui-root)
@reactRoot)
:hydrate-root! (fn [ui-root mount-node] (dom-client/hydrateRoot mount-node ui-root))})
:clj {}))
(defn with-react18
"Alters the rendering to support React 18"
[app]
#?(:cljs (let [reactRoot (volatile! nil)]
(-> app
(assoc-in
[:com.fulcrologic.fulcro.application/algorithms :com.fulcrologic.fulcro.algorithm/render-root!]
(fn [ui-root mount-node]
(when-not @reactRoot
(vreset! reactRoot (dom-client/createRoot mount-node)))
(.render ^js @reactRoot ui-root)
@reactRoot))
(assoc-in
[:com.fulcrologic.fulcro.application/algorithms :com.fulcrologic.fulcro.algorithm/hydrate-root!]
(fn [ui-root mount-node] (dom-client/hydrateRoot mount-node ui-root)))))
:clj app))