Read
Handlers are attributes
Event handlers live in Miso.Html.Event (E). Each one is an attribute that maps a DOM event to an action. Some carry data: E.onInput gives you the text of an input field.
data Action
= SetName MisoString
| Clear
view :: MisoString -> View () () MisoString Action
view name =
H.div_ []
[ H.input_
[ P.placeholder_ "Your name"
, P.value_ name
, E.onInput SetName
]
, H.button_ [ E.onClick Clear ] [ "Clear" ]
, H.p_ [] [ "Hello, ", text name ]
]E.onInput SetName means: on every keystroke, dispatch SetName applied to the field's current value. The action constructor carries the text, and update pattern matches on it.
update :: Action -> Effect () () MisoString Action
update (SetName s) = this .= s
update Clear = this .= ""