Halogen.Hooks.Hook
- Package
- purescript-halogen-hooks
- Repository
- thomashoneyman/purescript-halogen-hooks
#Hook Source
newtype Hook :: (Type -> Type) -> HookType -> Type -> Type
newtype 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
.
Instances
#HookAppend Source
data HookAppend :: HookType -> HookType -> HookType
data 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
#HookNewtype Source
class HookNewtype :: HookType -> HookType -> Constraint
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
#unsafeToHook Source
unsafeToHook :: forall m h a. UseHookF m a -> Hook m h a