Module

Marionette.ReactBasic

Package
purescript-marionette-react-basic-hooks
Repository
thought2/purescript-marionette-react-basic-hooks

#UseMarionette Source

newtype UseMarionette msg sta hooks

Opaque type of the useMarionette hook

#useMarionette Source

useMarionette :: forall msg sta. Eq sta => Config msg sta -> Hook (UseMarionette msg sta) (sta /\ (msg -> Effect Unit))

Main function of this library. it works in the same manner as e.g. useReducer.

import Marionette.Controllers.Monadic (mkController)

type State = Int
type Msg = CountUp | CountDown

control = case _ of
  CountUp -> modify_ (_ + 1)
  CountDown -> modify_ (_ - 1)

mkApp :: Component {}
mkApp = component "App" \_ -> React.do
  state /\ act <- useMarionette
    { initialState: 0
    , controller: mkController myControl
    }
  pure $
    R.div'
      [ R.div' [ text $ show state ]
      , R.button { onClick: handler_ $ act CountUp }
      ]