Wow! Which version of reagent/MUI? Did you use webpack for bundle? You didn't get warnings about ReactDOM incompatibilties?
Ah I see. Thank you @vishal.gautam for the explanation on the hooks. I can see how they would be quite valuable in daily React land.
does this method
(ns app.navigation
(:require
[reagent.core :as r]
["@material-ui/core" :refer [List ListItem Button]]
["@material-ui/styles" :refer [makeStyles]]
["@material-ui/icons" :refer [ExpandMore ExpandLess BarChart] :rename {ExpandMore ExpandMoreIcon
ExpandLess ExpandLessIcon}]))
do automatic tree shaking on advanced compilation? If so it might be worth learning the technique. Is this shadow-cljs?FWIW I made some benchmarking between reagent, helix https://clojurians.slack.com/archives/CRRJBCX7S/p1588066976025300
(using latest stable version of reagent 0.10.0, not 1.0.0), config is here https://github.com/krausest/js-framework-benchmark/pull/726/files)
how do you fire an event as soon as the component has loaded, i.e., onComponentMount?
Check out Form-3 components https://github.com/reagent-project/reagent/blob/master/doc/CreatingReagentComponents.md
that's slightly verbose though. Is that the recommended way?
Yeah, as far as I know thatβs the only way to do it, short of rolling your own interop with React and JS.
it's not that bad @pshar10 there are just some pitfalls to be aware of. Use them all the time (for better/worse), ping if you run into trouble
if for some reason you use them inline just remember they need to be wrapped in a vector
what pitfalls do I need to be aware of?
I use them with inputs frequently to focus/select on mount, i.e.
(reagent/create-react-class
{:componentDidMount
(fn [this]
(let [node (reagent.dom/dom-node this]
(.select node)
(.focus node)))
:reagent-render
(fn [] [:input])})
if you were to drop that inline, for instance, you would need to do something like
[:form
[:label "blah"]
[(reagent/create-react-class
{:componentDidMount
(fn [this]
(let [node (reagent.dom/dom-node this]
(.select node)
(.focus node)))
:reagent-render
(fn [] [:input])})]]
(note that it is wrapped in a vector)
as opposed to
[:form
[:label "blah"]
;; this won't work
(reagent/create-react-class
{:componentDidMount
(fn [this]
(let [node (reagent.dom/dom-node this]
(.select node)
(.focus node)))
:reagent-render
(fn [] [:input])})]
the other two pitfalls, I suppose, are to access the actual dom node from the lifecycle methods use reagent.dom/dom-node
as indicated in the example and to make sure that your your render method is actually :reagent-render
. If you use :render
it will have intermittent bugs
@goomba This is better I think:
(def foo-bar
(with-meta identity
{:component-did-mount
#((foo-bar))}))
(defn my-component []
[foo-bar
[:div "Foo"]
]
)
Cool! I've never seen that before π
@pshar10 With reagent 1.0.0 you can use functional components and react useState hooks.
Has anyone tried #respo and #reagent both? What are the pros and cons of both?
Which do you like better and why?