Module

Halogen.Hooks.Extra.Hooks.UseStateFn

Package
purescript-halogen-hooks-extra
Repository
jordanmartinez/purescript-halogen-hooks-extra

Idea and implementation by Thomas Honeyman. This was copied over from the Halogen Hooks repository's Examples folder.

#useStateFn Source

useStateFn :: forall b a m. (StateId a -> b) -> a -> Hook m (UseStateFn a) (Tuple a b)

Rather than writing this...

state /\ stateId <- useState 0
let modifyState = Hooks.modify_ stateId
pure (state /\ modifyState)

... one can write this code:

state /\ modifyState <- useStateFn Hooks.modify_ 0

See also useModifyState, which makes this even less boilerplate-y.

The function argument should be one of these four functions:

  • Hooks.modify_
  • Hooks.modify
  • Hooks.put
  • Hooks.get

#UseStateFn Source

newtype UseStateFn a hooks

Instances

#useModifyState Source

useModifyState :: forall a m. a -> Hook m (UseStateFn a) (Tuple a ((a -> a) -> HookM m Unit))