Fork me on GitHub
#helix
<
2021-04-30
>
Emmanuel John15:04:51

@lilactown Do you have a sponsor link for Helix?

lilactown17:04:37

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

👍 4
teh0xqb17:04:39

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)

lilactown17:04:38

it depends on what you need those defaultProps for

lilactown17:04:15

if you only want to provide a default value for fontSize in hte body of the component, you can use regular Clojure destructuring syntax

teh0xqb17:04:35

Right. I also added the example of "thirdPartyLibSettings" since I’m using another js library that expects some properties (other than defaultProps)

lilactown17:04:44

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

lilactown17:04:39

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

teh0xqb17:04:15

Thanks for getting back to me so quickly 👌

lilactown17:04:41

sure thing! happy hacking

wilkerlucio18:04:07

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

teh0xqb18:04:19

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

lilactown17:04:46

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

teh0xqb17:04:29

Ok 🙂 Works for me.