This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-04-04
Channels
- # announcements (28)
- # asami (12)
- # aws (3)
- # babashka (69)
- # babashka-sci-dev (34)
- # beginners (52)
- # biff (3)
- # calva (20)
- # clj-kondo (4)
- # cljsrn (4)
- # clojars (1)
- # clojure (90)
- # clojure-czech (2)
- # clojure-europe (33)
- # clojure-nl (11)
- # clojure-norway (35)
- # clojure-seattle (1)
- # clojure-uk (5)
- # clojurescript (87)
- # cursive (10)
- # datascript (5)
- # datomic (35)
- # defnpodcast (1)
- # emacs (8)
- # events (4)
- # fulcro (1)
- # google-cloud (2)
- # graphql (2)
- # hispano (2)
- # honeysql (5)
- # hoplon (2)
- # hugsql (1)
- # jobs (7)
- # kaocha (9)
- # lsp (102)
- # meander (13)
- # observability (7)
- # off-topic (56)
- # overtone (2)
- # pathom (47)
- # podcasts-discuss (1)
- # rdf (30)
- # reagent (16)
- # reitit (1)
- # releases (2)
- # remote-jobs (26)
- # rewrite-clj (10)
- # tools-deps (4)
- # vim (5)
- # vscode (4)
- # xtdb (41)
a react class i'm using want kind of input <TheReactClass value={50}>
. I wrapped it with (def the-react-class (r/adapt-react-class ...))
, so I can write hiccup.
but using it as [the-react-class {:value 50}]
ends up borked. do I need to do something else to mimic the value={50}
input?
no errors. it's a circular progress bar component that should be able to tackle any value 1-100, but when I just use e.g. :value 50
it behaves very weird - shows 75%. different for different values but almost never correct. assumed my input was somehow wrong.
not really, but it's not some fringe component either - it's v4 material ui circular progress https://v4.mui.com/components/progress/
I also need reminding how reagent translates prop names. if react expects e.g. alignItems="center"
, can I use either/or :alignItems "center" / :align-items "center"
Hi, I've managed to get a couple of react classes (AutoSizer & react-window) "working" in reagent. I've been working in pure cljs and avoiding react, so I'm wondering if there's a better way to to do this.
1. Is there anything obviously wrong? Are there helpers that make any of this more idiomatic reagent?
2. I'm not really sure where to break this up into components (maybe item + autosized list), I could see how to do this with a macro, but is there a place for more familiar reagent components?
3. the js->clj
conversion was difficult to track, autosizer's function isn't converted because of as-element
but reactify-component
does convert but not the nested style
Maybe there's some easier way to handle splatting react props in as they do in their docs?
(defn testlist []
(r/with-let [list-ref (atom nil)]
(let [things (range 1000)]
;;
[:> AutoSizer
{}
(fn [props]
(let [{:strs [width height]} (js->clj props)]
(r/as-element
;;
[:> rw/FixedSizeList
{:width width
:height height
:item-count (count things)
:item-size 64
:ref #(reset! list-ref %)}
(r/reactify-component
(fn [{:keys [index style] :as props}]
[:div
{:style (js->clj style)
:on-click #(.scrollToItem @list-ref index "center")}
(str "Item #" index)]))])))])))
Instead of {:strs [width height]} (js->clj props)
, just use JS interop: (.-width props)
and (.-height props)
.
What happens when you remove the call to js->clj
around style
? Are the styles not applied anymore? I'd expect the result to be correct to be honest.
Also, be wary about using js->clj
in such cases - as soon as some props
pass a ref that's expected down below, your code will break. It's not the case hear, but I tend to use a hand-written shallow-js->clj
for that.
• Instead of reactify-component, I'd just use a functional component and return a react element
• If it's easier you could just call createElement for the inner function, rather than use Reagent for that part
@U2FRKM4TW’s tips are good as well