Module

Elmish.Hooks.UseEffect

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

#traced Source

traced :: DebugWarning => Aff Unit -> Hook Unit

A version of useEffect that logs info from the name-generating function. Intended to be used with qualified imports: UseEffect.traced.

#traced' Source

traced' :: forall a. DebugWarning => Eq a => a -> (a -> Aff Unit) -> Hook Unit

A version of useEffect' that logs info from the name-generating function. Intended to be used with qualified imports: UseEffect.traced'.

#useEffect Source

useEffect :: Aff Unit -> Hook Unit

The useEffect hook takes an effect (Aff) to run and runs it in the init of the resulting component. E.g.:

todos :: ReactElement
todos = withHooks do
  todos /\ setTodos <- useState []

  useEffect do
    todos <- API.fetchTodos
    liftEffect $ setTodos todos

  pure $ H.fragment $ todoView <$> todos

#useEffect' Source

useEffect' :: forall a. Eq a => a -> (a -> Aff Unit) -> Hook Unit

This is like useEffect, but allows passing a value which, when it changes, will trigger the effect to run again. E.g.:

view :: ReactElement
view = withHooks do
  count /\ setCount <- useState 0

  useEffect' count \c -> liftEffect $
    HTMLDocument.setTitle ("You clicked " <> show c <> " times") =<< document =<< window

  pure H.button_ "" { onClick: setCount $ count + 1 } "Click me"