How to create a stateless and static Halogen component?

352 views Asked by At

Consider this snippet from github, https://github.com/slamdata/purescript-halogen/blob/master/examples/basic/src/Button.purs#L42 which tries to render an html button using halogen library.

render :: State -> H.ComponentHTML Query
  render state =
    let
      label = if state then "On" else "Off"
    in
      HH.button
        [ HP.title label
        , HE.onClick (HE.input_ Toggle)
        ]
        [ HH.text label ]

  eval :: Query ~> H.ComponentDSL State Query Message m
  eval = case _ of
    Toggle next -> do
      state <- H.get
      let nextState = not state
      H.put nextState
      H.raise $ Toggled nextState
      pure next
    IsOn reply -> do
      state <- H.get
      pure (reply state)

Is there any possible way to get the most 'barebone' UI control, just to render a static UI component, without states involved?

1

There are 1 answers

0
hdgarrood On

How about setting type State = Unit? Then your render function would look like

render :: State -> H.ComponentHTML Query
render _ = [...]

i.e. just ignore the parameter (since you can't get any information out of a Unit value anyway).