Skip to content

Instantly share code, notes, and snippets.

@fakenickels
Created December 13, 2018 19:27
Show Gist options
  • Save fakenickels/ae34c10d97ff25e7a98c5abd8582c14e to your computer and use it in GitHub Desktop.
Save fakenickels/ae34c10d97ff25e7a98c5abd8582c14e to your computer and use it in GitHub Desktop.
type hoc = ReasonReact.reactClass => ReasonReact.reactClass;
type router;
module WithRouter = {
[@bs.module "react-router"] external withRouter : hoc =
"withRouter";
type children = (~router: router) => ReasonReact.reactElement;
let component = ReasonReact.statelessComponent("WithRouter");
let make' = (~router: router, children: children) => {
...component,
render: (_self) => children(~router)
};
let jsComponent =
ReasonReact.wrapReasonForJs(
~component,
(props: {. "router": router, "children": children}) =>
make'(~router=props##router, props##children)
);
let enhanced = withRouter(jsComponent);
let make = (children: children) =>
ReasonReact.wrapJsForReason(~reactClass=enhanced, ~props=Js.Obj.empty(), children);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment