Module
Elmish.Hooks.UseState
- Package
- purescript-elmish-hooks
- Repository
- collegevine/purescript-elmish-hooks
#traced Source
traced :: forall state. DebugWarning => state -> Hook (state /\ (Dispatch state))
A version of useState
that logs messages, state changes, render times,
and info from the name-generating function. Intended to be used with
qualified imports: UseState.traced
.
#useState Source
useState :: forall state. state -> Hook (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 = withHooks do
visible /\ setVisible <- useState false
pure $
H.fragment
[ H.button_ "" { onClick: setVisible $ not visible } "Toggle visibility"
, if visible
then H.div "" "Content"
else H.empty
]