Module

Halogen.Hooks.Hook

#Hook

newtype Hook m h a

Instances

#HookAppend

data HookAppend :: HookType -> HookType -> HookType

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 (<>)

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

HookAppend as an infix operator

#Pure

data Pure :: HookType

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

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


#HookNewtype

class 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 Hooks.do
  -- ... use useState, useEffect in the implementation

#bind

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 = Hooks.do
  -- bind is necessary to use do-syntax with Hooks
  ... <- Hooks.useState ...

#discard

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 = Hooks.do
  ...
  -- discard is necessary to use do-syntax with Hooks
  Hooks.useLifecycleEffect ...

#pure

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

For use with qualified-do:

import Halogen.Hooks as Hooks

useMyHook = Hooks.do
  ...
  Hooks.pure ...

#unsafeFromHook

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

#unsafeToHook

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

Modules