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.

Next

How to structure the code