#Hook Source

newtype Hook :: (Type -> Type) -> HookType -> Type -> Typenewtype Hook m h a

A function which has access to primitive and custom hooks like UseState, UseEffect, UseRef, and UseMemo. Hook functions can be used to implement reusable, stateful logic and to implement Halogen components.

Functions of this type should be constructed using the Hooks API exposed by Halogen.Hooks.


#HookAppend Source

data HookAppend :: HookType -> HookType -> HookTypedata HookAppend t0 t1

A type for listing several Hook types in order. Typically this is used via the operator <>.

``purs import Halogen.Hooks (type (<>))

type UseStateEffect = UseState Int <> UseEffect <> Pure

-- using to the type UseStateEffect = HookAppend (UseState Int) (HookAppend UseEffect Nil)

#type (<>) Source

Operator alias for Halogen.Hooks.Hook.HookAppend (right-associative / precedence 1)

HookAppend as an infix operator

#Pure Source

data Pure :: HookTypedata Pure

The HookType used for pure, which lifts an arbitrary value into Hook.

``purs type UseX = UseState Int <> UseEffect <> Pure

#HookNewtype Source

class HookNewtype :: HookType -> HookType -> Constraintclass HookNewtype (a :: HookType) (b :: HookType) | a -> b

A class for asserting that one HookType can be "unwrapped" to produce the other. This class is used to turn a list of Hooks into a new opaque Hook in conjunction with wrap:

foreign import data UseX :: HookType

instance newtypeUseX :: HookNewtype UseX (UseState Int <> UseEffect <> Pure)

useX :: forall m. Hook m UseX Int
useX = Hooks.wrap
  -- ... use useState, useEffect in the implementation

#bind Source

bind :: forall h h' m a b. Hook m h a -> (a -> Hook m h' b) -> Hook m (h <> h') b

For use with qualified-do.

import Halogen.Hooks as Hooks

useMyHook =
  -- bind is necessary to use do-syntax with Hooks
  ... <- Hooks.useState ...

#discard Source

discard :: forall h h' m a. Hook m h Unit -> (Unit -> Hook m h' a) -> Hook m (h <> h') a

For use with qualified-do.

import Halogen.Hooks as Hooks

useMyHook =
  -- discard is necessary to use do-syntax with Hooks
  Hooks.useLifecycleEffect ...

#pure Source

pure :: forall h m a. a -> Hook m h a

For use with qualified-do:

import Halogen.Hooks as Hooks

useMyHook =
  Hooks.pure ...

#unsafeFromHook Source

unsafeFromHook :: forall m h a. Hook m h a -> Free (UseHookF m) a

#unsafeToHook Source

unsafeToHook :: forall m h a. UseHookF m a -> Hook m h a