File tree 1 file changed +26
-0
lines changed
1 file changed +26
-0
lines changed Original file line number Diff line number Diff line change @@ -106,6 +106,32 @@ The convention is `:size-<number>`, e.g size `20` is `:size-20`
106
106
- Try to make all other vars private because they should almost never be used
107
107
directly.
108
108
109
+ ## Default value when destructuring
110
+
111
+ Too often callers pass nil values because values can be wrapped in a ` when ` for example.
112
+ In this case, the default value is not applied, because : or macro will use default only when the value is absent.
113
+ Instead, use ` (or (:value props) some-default-value) ` in a ` let ` expression or as a parameter value.
114
+
115
+ ``` clojure
116
+ ; ; bad (unreliable)
117
+ (defn- view-internal
118
+ [{:keys [auto-focus?
119
+ init-value
120
+ return-key-type]
121
+ :or {auto-focus? false
122
+ init-value 0
123
+ return-key-type :done }}]
124
+ ... )
125
+
126
+ ; ; good
127
+ (defn- view-internal
128
+ [{:keys [theme size something] :as props}]
129
+ (let [auto-focus? (or (:auto-focus? props) false )
130
+ init-value (or (:init-value props) 0 )
131
+ return-key-type (or (:return-key-type props) :done )]
132
+ ...))
133
+ ```
134
+
109
135
## Component tests
110
136
111
137
We don't attempt to write component tests verifying how components look on the
You can’t perform that action at this time.
0 commit comments