Module
Elmish.Hooks.UseSubscription
- Package
- purescript-elmish-hooks
- Repository
- collegevine/purescript-elmish-hooks
#UseSubscription Source
data UseSubscription :: Type -> HookType
data UseSubscription t0
#useSubscription Source
useSubscription :: forall a. Subscription Aff a -> (a -> Aff Unit) -> Hook (UseSubscription a) Unit
Subscribes to the given subscription and calls the provided callback every time the subscription yields a value.
listenToNetwork :: Subscription Aff NetworkSignal
listenToNetwork = ...
view :: ReactElement
view = Hooks.component Hooks.do
lastSignal /\ setLastSignal <- Hooks.useState Nothing
useSubscription listenToNetwork \signal -> setLastSignal (Just signal)
Hooks.pure $
case lastSignal of
Nothing -> H.div "bg-secondary" "Waiting for signal..."
Just signal -> H.div "bg-success" $ "Received signal: " <> show signal