diff --git a/examples/with-reasonml/.bsb.lock b/examples/with-reasonml/.bsb.lock new file mode 100644 index 00000000..2fa3cf47 --- /dev/null +++ b/examples/with-reasonml/.bsb.lock @@ -0,0 +1 @@ +16836 \ No newline at end of file diff --git a/examples/with-reasonml/package.json b/examples/with-reasonml/package.json index d2b400bf..a1d8344d 100644 --- a/examples/with-reasonml/package.json +++ b/examples/with-reasonml/package.json @@ -10,12 +10,13 @@ "dependencies": { "babel-plugin-bucklescript": "^0.5.3", "next": "latest", - "react": "^16.4.2", - "react-dom": "^16.4.2", + "react": "^16.7.0", + "react-dom": "^16.7.0", "reason-react": "^0.5.3" }, "devDependencies": { - "bs-platform": "^4.0.5", - "concurrently": "^4.0.1" + "@babel/core": "^7.2.2", + "bs-platform": "^4.0.14", + "concurrently": "^4.1.0" } } diff --git a/examples/with-reasonml/pages/index.re b/examples/with-reasonml/pages/index.re index b87b0efe..f6d82098 100644 --- a/examples/with-reasonml/pages/index.re +++ b/examples/with-reasonml/pages/index.re @@ -1,13 +1,44 @@ let component = ReasonReact.statelessComponent("Index"); -let make = (_children) => { +let make = (~onServer, _children) => { ...component, - render: (_self) => + render: _self =>
-

(ReasonReact.string("HOME PAGE is here!"))

+

+ {ReasonReact.string("HOME PAGE is here!")} +
+ {ReasonReact.string("onServer: " ++ string_of_bool(onServer))} +

-
+ , }; -let default = ReasonReact.wrapReasonForJs(~component, (_jsProps) => make([||])); +let default = ReasonReact.wrapReasonForJs(~component, jsProps => make(~onServer=jsProps##onServer, [||])); + +/* The way to do getInitialProps: https://github.com/zeit/next.js/issues/4202#issuecomment-439175214 */ +let getInitialProps = context => + Js.Promise.make((~resolve, ~reject as _) => { + let onServer = + switch (Js.Nullable.toOption(context##req)) { + | None => false + | Some(_) => true + }; + resolve(. {"onServer": onServer}); + }); + +/* In 7.0.2 canary, you must remove the Js.Promise.make wrapper */ +/* + let getInitialProps = context => { + let onServer = + switch (Js.Nullable.toOption(context##req)) { + | None => false + | Some(_) => true + }; + {"onServer": onServer}; + }; + */ + +let inject = [%bs.raw {| (cls, fn) => cls.getInitialProps = fn |}]; + +inject(default, getInitialProps);