react-haskell

Haskell React bindings

https://github.com/joelburget/react-haskell

Latest on Hackage:2.0.1

This package is not currently in any snapshots. If you're interested in using it, we recommend adding it to Stackage Nightly. Doing so will make builds more reliable, and allow stackage.org to host generated Haddocks.

MIT licensed by Joel Burget
Maintained by [email protected]

This package provides high level bindings to Facebook's React library, meant for use with GHCJS.

React is a JavaScript library for building user interfaces. React (and React-Haskell) is focused on just UI - it's not a framework.

Currently React-Haskell can render simple stateful components, but not what React calls classes. Put another way, React-Haskell doesn't support lifecycle methods yet.

Here's a simple example which demonstrates basic elements, attributes, state, and handling events.

page_ :: ReactNode Void
page_ =
    let cls = smartClass
            -- this is a record and these should really be curly braces,
            -- but haddock breaks on them.
            [ name = "page"

            -- initially the input is empty
            , initialState = ""

            -- always transition to the input's new value
            , transition = \(_, value) -> (value, Nothing)

            , renderFn = \_ str -> div_ [ class_ "container" ] $ do
                input_ [ value_ str, onChange (Just . value . target) ]
            ]
    in classLeaf cls ()

main :: IO ()
main = do
    Just doc <- currentDocument
    Just elem <- documentGetElementById doc ("elem" :: JSString)
    render page_ elem