As crazy as it seems, using React and Haskell together just may be a good idea.
I was driven to create this thing because I had a large existing Haskell codebase I wanted to put online. However, even without existing code, I think a lot of problems are better modeled in Haskell than JavaScript or other languages. Or you might want to use some existing Haskell libraries.
Let's put a simple paragraph on the page:
sample :: React
sample = p <! className "style" $ em "andy warhol"
main :: IO ()
main = do
Just elem <- elemById "id"
render elem sampleThat creates a dom node on the page that looks like:
<p class="style">
<em>andy warhol</em>
</p>We can make that a little more complicated with some more child nodes.
sample :: React
sample = div <! className "beautify" $ do
"velvet underground"
input
"lou reed"But of course that input doesn't do anything. Let's change that.
sample :: StatefulReact JSString
sample = div $ do
"favorite artist:"
input <! onChange (updateState . targetValue)
text <$> getStateTODO
Jordan Walke sketched out a similar API for OCaml.
We should try to adhere to React's Virtual DOM Terminology when possible.