package server-reason-react

  1. Overview
  2. Docs
Legend:
Library
Module
Module type
Parameter
Class
Class type

What does universal code mean

The goal of server-reason-react is to enable running your client components in the server, but not only that, it also makes it easier to write code that can be shared between the server and the client. This is what we call universal code.

Challenges of universal code

One of the challenges of sharing code is that the server and the client platforms have different APIs available. You can't use browser's APIs on the server, such as document.querySelectorAll and you can't use server related APIs on the client such as any filsystem operations.

In this aspect server-reason-react is not much different than Node.js. Node.js doesn't provide the global window/document objects and leaves the user to ensure the usages of those are handled manually.

In our case, we don't have any implementation for the browser APIs but we need the code to compile, so we provide a few utilities to make it easier to have code compiled.

Universal modules from server-reason-react

server-reason-react comes with a few modules that are compatible with both server and client, to make it easier to write universal code and don't worry about the platform.

  • Belt is an implementation of Belt that would work on both server and client. server-reason-react.belt (Unstable)
  • Js is an half-implementation of the Js module from melange.js, and many parts aren't implemented and some other parts aren't possible to implement on the server (Unstable, it raises "NOT IMPLEMENTED" for missing functions). server-reason-react.js
  • Webapi is a shimmed version of melange-webapi that works crash at runtime if you call those APIs on the server. server-reason-react.webapi

Next

How to structure the code

OCaml

Innovation. Community. Security.