Created
May 25, 2015 12:31
-
-
Save vvvvalvalval/937f69ef04872b649e82 to your computer and use it in GitHub Desktop.
Managing the lifecycle of stateful reagent components with single-item :key-ed seqs
This file contains hidden or 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
;; Instead of this version, where you have to manage the lifecycle of my-stateful-component with React lifecycle methods | |
(defn parent-component [] | |
[:div | |
;; ... | |
[my-stateful-component dynamic-id arg1 arg2 etc.] | |
;; ... | |
]) | |
;; ... you can use this trick | |
(defn parent-component [] | |
[:div | |
;; ... | |
(list ^{:key dynamic-id} [my-stateful-component dynamic-id arg1 arg2 etc.]) ;; whenever dynamic-id changes, my-stateful-component will be 'reinitialized'. | |
;; ... | |
]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment