Fix 'unknown prop' react warning

This commit is contained in:
Teemu Patja 2017-01-30 21:34:12 +02:00
parent c60db00f6d
commit 993b2a5064
No known key found for this signature in database
GPG Key ID: F5B7035E6580FD4C
1 changed files with 16 additions and 14 deletions

View File

@ -4,26 +4,28 @@
(defn input [{:keys [value-path] :as props}]
(let [init-val @(rf/subscribe [:get-in value-path])
props-clean (dissoc props :value-path)
val (reagent/atom init-val)
save #(let [v (-> @val str clojure.string/trim)]
(when (seq v)
(rf/dispatch [:assoc-in value-path v])))]
(when (seq v)
(rf/dispatch [:assoc-in value-path v])))]
(fn []
[:input.form-control
(merge props {:type "text"
:value @val
:on-blur save
:on-change #(reset! val (-> % .-target .-value))})])))
(merge props-clean {:type "text"
:value @val
:on-blur save
:on-change #(reset! val (-> % .-target .-value))})])))
(defn checkbox [{:keys [value-path on-change]}]
(let [init-val @(rf/subscribe [:get-in value-path])
val (reagent/atom init-val)]
(fn [props]
[:input.form-control
(merge {:type "checkbox"
:checked @val
:onChange #(let [new-val (not @val)]
(on-change)
(rf/dispatch [:assoc-in value-path
(reset! val new-val)]))}
props)])))
(let [props-clean (dissoc props :value-path)]
[:input.form-control
(merge {:type "checkbox"
:checked @val
:on-change #(let [new-val (not @val)]
(on-change)
(rf/dispatch [:assoc-in value-path
(reset! val new-val)]))}
props-clean)]))))