Created
June 13, 2017 13:05
-
-
Save pesterhazy/33d5ac78629b11c5120c58b81d5e8114 to your computer and use it in GitHub Desktop.
Reagent forcing a remount
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; 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}]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This saved my life today! Thanks for sharing.