Module

Elmish.Hooks.UseState

Package
purescript-elmish-hooks
Repository
collegevine/purescript-elmish-hooks

#UseState Source

data UseState :: Type -> HookTypedata UseState t0

#traced Source

traced :: forall @state. DebugWarning => state -> Hook (UseState state) (state /\ (Dispatch state))

A version of useState that logs messages, state changes and render times. Intended to be used with qualified imports: UseState.traced.

#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
    ]