package server-reason-react
Install
dune-project
Dependency
Authors
Maintainers
Sources
sha256=f7e93b2c24e6420ed7352f5b04ff028ea6ea8b9b91679bbce43aadfcae028f34
sha512=b74f883d8fad95738b7dd9b51f23af27ef1b541939ad9b8ea65cfb0d48a217c2265ca9319e9355c7782bf223a5168ee4ff236677503afa301c8b7b08561fcd8c
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))