This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-04-19
Channels
- # announcements (37)
- # aws (6)
- # babashka (12)
- # babashka-sci-dev (16)
- # beginners (83)
- # biff (10)
- # cider (14)
- # cljdoc (26)
- # cljs-dev (20)
- # clojure (123)
- # clojure-czech (9)
- # clojure-europe (26)
- # clojure-nl (4)
- # clojure-norway (20)
- # clojure-spec (7)
- # clojure-uk (6)
- # clojured (14)
- # clojurescript (28)
- # cursive (5)
- # datalevin (8)
- # datomic (3)
- # duct (6)
- # emacs (26)
- # events (2)
- # fulcro (7)
- # gratitude (1)
- # holy-lambda (19)
- # integrant (1)
- # jobs (2)
- # leiningen (8)
- # lsp (7)
- # nyc (1)
- # pathom (70)
- # re-frame (8)
- # reagent (15)
- # releases (1)
- # sci (8)
- # shadow-cljs (117)
- # testing (5)
- # tools-deps (11)
- # vim (5)
I'm trying to follow some MUI examples, and I'm not sure how to translate this to clojurescript/reagent:
function ValueLabelComponent(props: Props) {
const { children, value } = props;
return (
<Tooltip enterTouchDelay={0} placement="left" title={value}>
{children}
</Tooltip>
);
}
Any pointers?There is pretty good documentation available at the Reagent github repo, including examples on how to deal with props. Maybe that can help? https://github.com/reagent-project/reagent/blob/master/doc/InteropWithReact.md
Yes, I'm very familiar with that page. I personally think all the docs are written as if we are all react experts, which sadly I am not. That's why I find names like argv
for functions that deal with props to be rather obscure and not particularly illuminating.
(defn value-label-component
[props]
(let [value (:value props)
children (:children props)]
[mui-tooltip/tooltip {:placement "bottom" :title value}
children]))
I can't test it where I am now. Looks like you may be missing a (reagent/current-component) to access the props and children. I remember an article I read on this once, let me see if I can find it
It's a bit older, but will probably still be valid: https://presumably.de/reagent-mysteries-part-4-children-and-other-props.html
(:require ["@mui/material" :refer [Tooltip]]) ; inyour ns
(def tooltip (reagent/adapt-react-class Tooltip))
Then you can just use tooltip as a reagent function would
In your case it will be:
(defn value-label-component [{:keys [children value]}]
[tooltip {:enter-touch-delay 0 :placement "left" :title value} children])
You can also use the :>
syntax as a shorthand for adapt-react-class:
(:require
["@mui/material" :refer [Tooltip]] ;; or maybe :default Tooltip (without []) instead of :refer [Tooltip]
(defn value-label-component [{:keys [children value]}]
[:> Tooltip {:enter-touch-delay 0 :placement "left" :title value} children])
The above require is with using shadow-cljs and npm. Also see https://github.com/reagent-project/reagent/blob/master/doc/ReactFeatures.mdYeah, I think there are good arguments for both approaches, I think when using a library like material having the tags in more uniform syntax to reagent makes sense because it will be almost everywhere and also needs to be reusable. I often create a separate namespace where I adapt all the external react components I need
It is also how I approach making react native apps, I just copy all the adapt react classes from a previous project and reuse them. I think this is a nicer approach than using or creating a wrapper library because it gives you more control over what you import and how it is used.