helix

https://github.com/Lokeh/helix
Emmanuel John 2021-04-30T15:13:51.043900Z

@lilactown Do you have a sponsor link for Helix?

teh0xqb 2021-04-30T17:20:39.047500Z

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)

lilactown 2021-04-30T17:26:37.047600Z

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

👍 1
lilactown 2021-04-30T17:27:38.048300Z

it depends on what you need those defaultProps for

lilactown 2021-04-30T17:28:15.049600Z

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

teh0xqb 2021-04-30T17:28:35.050400Z

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

lilactown 2021-04-30T17:28:44.050500Z

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

lilactown 2021-04-30T17:29:39.051300Z

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

lilactown 2021-04-30T17:29:46.051700Z

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

teh0xqb 2021-04-30T17:30:29.052600Z

Ok 🙂 Works for me.

teh0xqb 2021-04-30T17:31:15.052800Z

Thanks for getting back to me so quickly 👌

lilactown 2021-04-30T17:31:41.053100Z

sure thing! happy hacking

wilkerlucio 2021-04-30T18:15:07.053400Z

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

teh0xqb 2021-04-30T18:28:19.053600Z

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