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?(defn inputer-username [state set-state]
(d/input {:value (:username state) :on-change #(set-state assoc :username (.. % -target -value))))
(defn button-clear-values [state set-state]
(d/button {:on-click (do (set-state state assoc :username "") (set-state state assoc :password ""))))
?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.
https://reactjs.org/docs/thinking-in-react.html is a good starting point, if you’re new to React
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/>
)
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 %)})
@https://app.slack.com/team/U4YGF4NGM I see, you pass informations as hash-map. Thanks