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