Skip to content

Instantly share code, notes, and snippets.

@pesterhazy
Created June 13, 2017 13:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pesterhazy/33d5ac78629b11c5120c58b81d5e8114 to your computer and use it in GitHub Desktop.
Save pesterhazy/33d5ac78629b11c5120c58b81d5e8114 to your computer and use it in GitHub Desktop.
Reagent forcing a remount
;; This snippet forces React to unmount and remount the
;; entire component tree. Note that this is not the same
;; as using r/force-update-all. r/force-update-all causes
;; all components to update while staying mounted; the technique
;; used here causes a complete did-unmount/did-mount cycle.
(defonce !refresh-count (r/atom 0))
(defn refresh []
(swap! !refresh-count inc))
(defn root* []
(r/create-class
{:component-did-mount (fn []
(prn [:did-mount :root*]))
:render (fn []
[:div "hello"])}))
(defn root []
[root* {:key @!refresh-count}])
@euporos
Copy link

euporos commented Apr 6, 2021

This saved my life today! Thanks for sharing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment