helix

https://github.com/Lokeh/helix
fabrao 2020-03-30T19:22:13.020100Z

I´m little confuse about using state and how to organize it at all. If I have a state that hold username and password , what is the best way to use it?

(let [[state set-state] (hooks/use-state {:username "" :password ""})]
  (input-username state set-state)
  (input-password state set-state)
  (button-clear-values state set-state)
)
is this the best way to do this?

fabrao 2020-03-30T19:24:53.021700Z

(defn inputer-username [state set-state]
      (d/input {:value (:username state) :on-change #(set-state assoc :username (.. % -target -value))))

fabrao 2020-03-30T19:26:48.023600Z

(defn button-clear-values [state set-state]
      (d/button {:on-click (do (set-state state assoc :username "") (set-state state assoc :password ""))))
?

lilactown 2020-03-30T19:30:14.024400Z

hey Fabrao. helix is a pretty thin wrapper around React; so you’ll want to get to know what React best practices are for working with helix.

lilactown 2020-03-30T19:30:24.024700Z

https://reactjs.org/docs/thinking-in-react.html is a good starting point, if you’re new to React

lilactown 2020-03-30T19:32:52.026900Z

you’ll want to create components (in helix we use defnc instead of class or function in JS) which take props, and then create elements out of those components (in helix we use the $ macro like ($ component-name) to create elements instead of writing <ComponentName/>)

lilactown 2020-03-30T19:35:53.029400Z

an example might be:

(defnc username-input
  [{:keys [username on-change]}]
  (d/input
   {:value username
    :on-change #(on-change (.. % -target -value))}))

;; in your component where state is created
($ username-input
   {:username (:username state)
    :on-change #(set-state assoc :username %)})

fabrao 2020-03-30T20:31:57.030100Z

@https://app.slack.com/team/U4YGF4NGM I see, you pass informations as hash-map. Thanks