This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2021-04-30
Channels
- # asami (10)
- # babashka (14)
- # beginners (71)
- # calva (56)
- # cider (8)
- # cljs-dev (3)
- # clojure (111)
- # clojure-australia (1)
- # clojure-europe (19)
- # clojure-nl (4)
- # clojure-uk (147)
- # clojurescript (4)
- # cursive (8)
- # datalog (1)
- # datomic (19)
- # emacs (4)
- # graalvm (32)
- # helix (14)
- # jackdaw (7)
- # jobs-discuss (10)
- # juxt (4)
- # lsp (3)
- # malli (47)
- # meander (6)
- # off-topic (29)
- # portal (6)
- # re-frame (1)
- # react (3)
- # reitit (24)
- # releases (1)
- # remote-jobs (4)
- # reveal (33)
- # rewrite-clj (3)
- # shadow-cljs (5)
- # sql (10)
- # tools-deps (4)
- # vim (7)
- # xtdb (151)
@lilactown Do you have a sponsor link for Helix?
Hello all! I’m using helix and am wondering if there’s a recommended practice to set defaultProps or other properties on the function used to create the component. eg I’m looking to translate:
const App = ({name, fontSize}) => <p style={{fontSize}}>{name}</p>;
App.defaultProps = {fontSize: 100};
App.thirdPartyLibSettings = { /*...*/}
I currently use set!
:
(defnc App [{:keys [name fontSize]}] (d/p {:style {:fontSize fontSize}} name))
(set! App -defaultProps (clj->js {:fontSize 100}))
(set! App -thirdPartyLibSettings (clj->js { #_"..." }))
The above method works. I wonder if there’s a cleaner way (a macro could do, but maybe something less involved/verbose that I didn’t consider)if you only want to provide a default value for fontSize
in hte body of the component, you can use regular Clojure destructuring syntax
Right. I also added the example of "thirdPartyLibSettings"
since I’m using another js library that expects some properties (other than defaultProps)
for 3rd party libraries that expect a property to be set on the component, I think set!
is the best way to do it
another good option is to use goog.object/set
, then you are sure to don’t have issues during advanced compilation