Skip to content

Instantly share code, notes, and snippets.

@vvvvalvalval
Created May 25, 2015 12:31
Show Gist options
  • Save vvvvalvalval/937f69ef04872b649e82 to your computer and use it in GitHub Desktop.
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
;; 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