Skip to content

Commit

Permalink
Add hydrate-root to client ns
Browse files Browse the repository at this point in the history
  • Loading branch information
Deraen committed Nov 11, 2022
1 parent 9aeab6c commit e67d4f8
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/reagent/dom/client.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
(.unmount root))

(defn- reagent-root [^js js-props]
;; This will flush initial r/after-render callbacks.
;; Later that queue will be flushed on Reagent render-loop.
(let [el (gobj/get js-props "comp")]
(react/useEffect (fn []
(binding [util/*always-update* false]
Expand All @@ -37,3 +39,11 @@
;; render, and handles the *always-update* binding correctly?
comp (fn [] (p/as-element compiler el))]
(.render root (react/createElement reagent-root #js {:comp comp})))))

(defn hydrate-root
([container el]
(hydrate-root container el nil))
([container el {:keys [compiler on-recoverable-error identifier-prefix]
:or {compiler tmpl/*current-default-compiler*}}]
(let [comp (fn [] (p/as-element compiler el))]
(react-dom-client/hydrateRoot container (react/createElement reagent-root #js {:comp comp})))))

0 comments on commit e67d4f8

Please sign in to comment.