This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2018-04-29
Channels
- # beginners (1)
- # cider (7)
- # cljsrn (6)
- # clojars (3)
- # clojure (35)
- # clojure-nl (2)
- # clojure-spec (5)
- # clojure-uk (9)
- # clojurescript (18)
- # clojurex (1)
- # community-development (2)
- # cursive (27)
- # datomic (12)
- # duct (11)
- # emacs (5)
- # hoplon (5)
- # immutant (2)
- # leiningen (1)
- # luminus (15)
- # nyc (1)
- # om (9)
- # om-next (5)
- # onyx (55)
- # parinfer (1)
- # re-frame (3)
- # reagent (44)
- # reitit (11)
- # ring-swagger (4)
- # shadow-cljs (25)
- # videos (1)
[(r/adapt-react-class DragDropContext) ...
[(r/adapt-react-class Droppable) ...
(fn [pr sn]
(r/as-element [:div ...]))]]
@lwhorton☝️ this works, except that because you’re returning a fn (instead of a vector with a component in the first index) now reagent atom derefs no longer trigger a rerender. i guess that’s a different problem, though
if you do, let me know! I’m working on a lib for working with React 16 context and it’s a problem
hmm.. yea i’ll have to dig around. I wonder if it has to be lib-specific with some sort of “force rerender” option. or maybe I can wrap my inner fn with r/create-class
and do a manual setState somewhere?
I’m not familiar with how exactly Reagent executes the re-rendering, so I’m not sure
what I’ve done so far is basically keep the render-fn components as “stateless” leafs that only depend on their props & value(s) passed in through the render-fn
yea it’s a problem as soon as anything inside a drag-n-drop needs to modify state via some button, for example
I find myself doing this kind of thing a lot:
(defn component [props & children]
(into [:div "a thing"] children))
so that I can pass arbitrary number of children into a componentwell, you could just [:div "a thing" children]
? Or perhaps, that’s not what you’re asking? 🙂
I use something along the lines of ...
(defn only-child []
(let [children (r/children (r/current-component))]
(when (not= (count children) 1)
(throw (js/Error. "Only one child allowed")))
(first children)))
(defn authwall-ui []
(if authenticated?
(only-child)
[:div "Not authenticated"]))
Then you can use the authwall wrapper by passing in another hiccup form:
[authwall-ui [content-ui]]]
(I use use the -ui
suffix to man "this is a reagent component")
@reefersleep it would get passed in as e.g. [:div "a thing" [[:div "another thing"]]]
True that. I’ve put seqs at the end of hiccup vectors, though; [:div 1 (list 7 3 4)]
is valid hiccup. Don’t know if that helps you 🙂
Wait, what
You’re doing & children
in your arguments definition. That means that it is a list, and not a vector. You should be able to put it at the end of a vector literal.
I’m doing the exact same thing in my code 🙂
oh yeah, but that’s nothing to do with the distinction between vector/list
For some reason (that I have inklings about, but no true knowledge about), React likes to be able to distinguish between individual elements of a list via their key property. I think that is what is meant by those warnings, anyway.
I often define a simple function for adding the keys in my reagent projects:
(defn add-react-keys
“Assigns unique ‘key’ props to the ‘components’ seq elements.
React gives a ‘warning’ if each element of a seq does not have a unique ‘key’ prop. ”
[components]
(map (fn [component]
(with-meta component {:key (random-uuid)}))
components))
You could also do (map-indexed (fn [index component] (with-meta component {:key index})) components)
Also, there’s a shorthand for adding the meta data
(map-indexed
(fn [index component]
^{:key index} component)
components)
If you’re using a library that does animations on your list, however, you need to identify your list elements uniquely and persistently for the transitions to work correctly. But don’t worry about if you aren’t using such a lib.
And yeah, it sucks that you have to call add-react-keys
everywhere, just as it sucks to call into
everywhere. Too bad
¯\(ツ)/¯
You could write a macro to handle it for you…
@U4YGF4NGM (just want to make sure you get this)
@pesterhazy I specifically want to be able to pass in an arbitrary amount of children, though
just published a lib for easy use of React’s new context API: https://github.com/Lokeh/reagent-context ⚛️ 🎉
sweet!
and if anyone can figure this out it’ll really go from good to great 😅 https://github.com/Lokeh/reagent-context#gotchas
iiinteresting. the fact that ratoms aren’t bound inside of render functions does seem to be simply because they’re not used in a [component …] form
You’re doing & children
in your arguments definition. That means that it is a list, and not a vector. You should be able to put it at the end of a vector literal.
I’m doing the exact same thing in my code 🙂