reagent-project/reagent-forms

Component State

Open

#137 建立於 2018年3月12日

在 GitHub 查看
 (8 留言) (0 反應) (0 負責人)HTML (78 fork)batch import
enhancementhelp wanted

倉庫指標

Star
 (337 star)
PR 合併指標
 (30 天內沒有已合併 PR)

描述

Hey there! I'm trying to track the state change of an input to apply various CSS classes to it based on valid/invalid state.

For some reason it doesn't seem like the input is being re-rendered after I update component state on blur when I'm using () to implement the inputs. Strangely enough, I can see the event firing via console log when I render the input as [] but the actual state updating still does not happen.

Here's a snippet, ignore some of the random stuff in there. The key piece here is the swap! on-blur:

(defn input [label type id error-id]
  (let [key (keyword (name id))
        component-state (r/atom {:count 0})]
    (js/console.log "hi" label (get @component-state :count))
   [:div.col-sm-6
    [:label.input-label label]
    [:div.input-container
     [:input.input-field.form-control
      {:field type
       :id id
       :on-blur #(swap! component-state update-in [:count] inc)}]
     [:div.error-container {:field :alert :id error-id}]]]))

貢獻者指南