Skip to content

Instantly share code, notes, and snippets.

@quicksnap
Created April 5, 2017 22:47
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save quicksnap/d31d06d5a83bb046653db2af572897e8 to your computer and use it in GitHub Desktop.
Save quicksnap/d31d06d5a83bb046653db2af572897e8 to your computer and use it in GitHub Desktop.
Crappy React-router v4 bindings
external router : ReactRe.reactClass = "BrowserRouter" [@@bs.module "react-router-dom"];
external link : ReactRe.reactClass = "Link" [@@bs.module "react-router-dom"];
external route : ReactRe.reactClass = "Route" [@@bs.module "react-router-dom"];
module Router = {
let createElement children::(children: list ReactRe.reactElement) =>
ReactRe.wrapPropsShamelessly router {"children": Array.of_list children} ::children;
};
module Link = {
let createElement
className::(className: option string)=?
children::(children: list ReactRe.reactElement)
linkTo::(linkTo: string) =>
ReactRe.wrapPropsShamelessly
link
{
"to": linkTo,
"children": Array.of_list children,
"className": Js_null_undefined.from_opt className
}
::children;
};
module Route = {
let createElement
path::(path: string)
exact::(exact: bool)=false
component::(component: option ReactRe.reactClass)=? =>
ReactRe.wrapPropsShamelessly
route
{
"path": path,
"exact": Js.Boolean.to_js_boolean exact,
"component": Js.Null_undefined.from_opt component
};
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment