package universal-portal
Universal Portal for ssr natively ReasonReact apps
Install
Dune Dependency
Authors
Maintainers
Sources
0.2.0.tar.gz
md5=aa3cf95dceca01ac94ae9f016aa03b1e
sha512=2bb000c6091ae3a7227687c1d2e0a3a5dcbbd324ed5e5476cf70346df652e4c5e10135946ecb968fcbb5b6369b2816c6b38926205d90fd64d7d5733efce56c6b
Description
Published: 11 Apr 2024
README
README.md
Universal Reason Portal
Universal Portal for ssr natively ReasonReact apps.
This project was inspired by server-reason-react to understand how SSR with ReasonReact works and also give the community more material to learn about SSR with ReasonReact.
Table of Contents
Installation
opam install universal-portal
Usage
Server
Dream.router([
Dream.get("/", _request => {
let portals: ref(array(UniversalPortal_Shared.Components.Portal.portal)) = ref([||]);
let element =
ReactDOM.renderToString(
UniversalPortal_Server.collectPortals(
<Page scripts=["/static/app.js"]>
<Shared_native_demo.App />
</Page>,
(collectedPortal: UniversalPortal_Shared.Components.Portal.portal) => {
portals := Array.append(portals^, [|collectedPortal|])
}),
);
let html =
UniversalPortal_Server.appendUniversalPortals(element, portals^);
portals := [||];
html |> Dream.html;
}),
Dream.get("/static/**", Dream.static("./static")),
]);
Shared
For client dune config add
(libraries universal-portal.shared_js)
For native dune config add
(libraries universal-portal.shared_native)
Component
Use UniversalPortal_Shared
and it will work on both client and native content.
[@react.component]
let make = () => {
<div>
<UniversalPortal_Shared.Components.Portal selector="body">
<div>
{"Hey, I'm a portal, disable JS on your dev tools and check that I'll still here"
|> React.string}
</div>
</UniversalPortal_Shared.Components.Portal>
</div>;
};
Cleaning server side portals
You must call the UniversalPortal_Shared.Hooks.UseRemoveServerPortals.make
at the main entry point of your app, so it will remove all the server side portals.
Checkout the demo for more details: Demo
UniversalPortal_Shared.Hooks.UseRemoveServerPortals.make();
Running the demo
Make sure to initialize the project:
make init
Then you can run the demo:
make demo
Roadmap
[ ] Improve tests
Dependencies (11)
- reason-react
- lambdasoup
- reason-react-ppx
-
server-reason-react
<= "0.1.0"
- quickjs
- dream
- melange-webapi
- melange
-
reason
>= "3.10.0"
-
ocaml
>= "5.0.0"
-
dune
>= "3.8"
Dev Dependencies (8)
-
odoc
with-doc
-
ocaml-lsp-server
with-test
-
melange-jest
with-test
-
melange-testing-library
with-test
-
ocamlformat
= "0.26.1" & with-test
-
fmt
with-test
-
alcotest-lwt
with-test
-
alcotest
with-test
Used by
None
Conflicts
None
sectionYPositions = computeSectionYPositions($el), 10)"
x-init="setTimeout(() => sectionYPositions = computeSectionYPositions($el), 10)"
>
On This Page