Module
Elmish.Hooks.UseState
- Package
- purescript-elmish-hooks
- Repository
- collegevine/purescript-elmish-hooks
#useState Source
useState :: forall @state. state -> Hook (UseState state) (state /\ (Dispatch state))
The useState
hook takes an initial state and returns a Hook
encapsulating the current state and a setState
function. E.g.:
view :: ReactElement
view = Hooks.component Hooks.do
visible /\ setVisible <- useState false
Hooks.pure $
H.fragment
[ H.button_ "" { onClick: setVisible <| not visible } "Toggle visibility"
, if visible
then H.div "" "Content"
else H.empty
]