package server-reason-react
Install
dune-project
Dependency
Authors
Maintainers
Sources
sha256=b97fbe6a7c3e5e1a7775e0f6498f257acaaa7e272177a9a3e0e50b7a49408d7c
sha512=b27a94618c367c80efef83a41c2a59c9cc7848fd753049ed40fa1f2cface1ef34cf3a995835bf08e2eb59c3186911f429b4706ed07dcb9724df6af5eb012a31d
doc/get-started.html
Getting started with server-reason-react
This documentation will explain the different modules available in server-reason-react, and how to use them, however it is assumed a minimum understanding of Reason, reason-react, Melange and a bit of dune.
Let's start with a React component written in Reason:
module Greetings = {
[@react.component]
let make = (~name) => {
<div>
<h1> {React.string("Hello " ++ name)} </h1>
</div>
}
};A module with a make function that returns a React.element. This component is both a reason-react component and a server-reason-react component.
server-reason-react provides React and ReactDOM modules with the same interface as reason-react, including the JSX transformation via server-reason-react.ppx.
The main difference is, with server-reason-react you can render it on the server with ReactDOM (server-reason-react.reactDom):
let html = ReactDOM.renderToStaticMarkup(<Greetings name="visitor" />)
// <div><h1>Hello visitor</h1></div>This is usually part of your server-side code
The ReactDOM module exposes the renderTo* methods: ReactDOM.renderToStaticMarkup, ReactDOM.renderToString and ReactDOM.renderToLwtStream.
Install from opam's registry (recommended)
opam install server-reason-reactInstall from source
If you want to use the development version of server-reason-react, you can install it via opam pinning:
opam pin server-reason-react.dev "https://github.com/ml-in-barcelona/server-reason-react.git#main" -yUsage
Add server-reason-react.react and server-reason-react.reactDom to your dune file:
(libraries (server-reason-react.react server-reason-react.reactDom) and also server-reason-react.ppx to your preprocess list
(preprocess (pps server-reason-react.ppx))