Skip to content

Instantly share code, notes, and snippets.

@sync
Created May 4, 2019 02:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sync/de41f65adea48ca764c275004b32fced to your computer and use it in GitHub Desktop.
Save sync/de41f65adea48ca764c275004b32fced to your computer and use it in GitHub Desktop.
Next.js
type css = {. "about": string};
[@bs.module] external css: css = "./about.css";
[@react.component]
let make = (~onServer) => {
<div
className={
css##about;
}>
<p> {React.string("This is the about page.")} </p>
<p> {React.string("onServer: " ++ string_of_bool(onServer))} </p>
<Counter />
</div>;
};
let getInitialProps = context => {
let onServer =
switch (Js.Nullable.toOption(context##req)) {
| None => false
| Some(_) => true
};
{"onServer": onServer};
};
let default = make;
let inject:
(
Js.t('a) => React.element,
{. "req": Js.Nullable.t(Js.t('a))} => Js.t('a)
) =>
unit = [%bs.raw
{| (cls, fn) => cls.getInitialProps = fn |}
];
inject(default, getInitialProps);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment