reagent-project/reagent-forms

Component State

Open

#137 ouverte le 12 mars 2018

Voir sur GitHub
 (8 commentaires) (0 réactions) (0 assignés)HTML (78 forks)batch import
enhancementhelp wanted

Métriques du dépôt

Stars
 (337 stars)
Métriques de merge PR
 (Aucune PR mergée en 30 j)

Description

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}]]]))

Guide contributeur