Skip to content

Instantly share code, notes, and snippets.

@jmlsf
Last active July 20, 2018 19:55
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 jmlsf/7fe736c8b6d7f236361aaad59a1113fd to your computer and use it in GitHub Desktop.
Save jmlsf/7fe736c8b6d7f236361aaad59a1113fd to your computer and use it in GitHub Desktop.
Reagent Form-3 component-did-update
(def atm (reagent/atom "foo"))

(defn f3
  [a b]
  (js/console.log "test-component")
  (reagent/create-class
    {:display-name "test"
     :component-did-update
       (fn [this prev-argv]
         (print "prev-argv = " prev-argv)
         (print "argv = " (reagent/argv this))
         (print "props = " (reagent/props this))
         (print "children = " (reagent/children this)))
     :reagent-render
       (fn [a b]
         [:div (str (:val a) b)])}))

(defn test-component []
  [f3 {:val @atm} @atm])

(js/setTimeout (fn []
                 (js/console.log "updating")
                 (reset! atm "FOO"))
               1)

=>

new-state =  cljs.core/PersistentHashMap [count: 9]
test-component
updating
prev-argv =  [#object[Constructor] {:val foo} foo]
argv =  [#object[Constructor] {:val FOO} FOO]
props =  {:val FOO}
children =  [FOO]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment