Fork me on GitHub
#helix
<
2020-09-11
>
Aron13:09:16

I am a bit lost on how to write best default props. I am using material ui AutoComplete. This has props such as autoComplete which is set to false as default. I would like to invert this and have a different, more specific component but still general, that is called PredictiveInput and it has autoComplete by default set to true. Then, I would like to be able to use ($ PredictiveInput ...) without specifying autoComplete for when it is true, and ($ PredictiveInput {:autoComplete false ...}) when I want to turn it off. The only problem is that in PredictiveInput component I am now writing stuff like ($ AutoComplete {:autoComplete (if (not (nil? auto-complete)) auto-complete true) and because there are several of these options that I would like to configure, it's a bit heavy, too much repetition, hard to see what is going on.

lilactown16:09:48

do Clojure destructuring defaults work for this case?

lilactown16:09:19

(defnc predictive-input
  [{:keys [auto-complete]
    :or {auto-complete true}]
  ,,,)
?

👍 3
dominicm16:09:19

That's how I've been doing it

Aron23:09:22

thanks, I am totally new to this