helix 2021-04-30

@lilactown Do you have a sponsor link for Helix?

I don't yet. I'll post it here if I do ever set one up

👍 1

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)

it depends on what you need those defaultProps for

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)

(defnc App
  [{:keys [name fontSize] :or {fontSize 100}]
  ,,,)

for 3rd party libraries that expect a property to be set on the component, I think set! is the best way to do it

Thanks for getting back to me so quickly 👌

sure thing! happy hacking

another good option is to use goog.object/set, then you are sure to don’t have issues during advanced compilation

Ah, we’ll keep that in mind. Thanks!

I don't think there's much that helix could improve on there

Ok 🙂 Works for me.