Skip to content

Instantly share code, notes, and snippets.

Last active Jan 1, 2021
What would you like to do?
ReasonReact Context API Example
module StringContext =
type t = string;
let defaultValue = "Awesome";
let component = ReasonReact.statelessComponent("Tree");
let make = _children => {
render: _self =>
<StringContext.Provider value="Hello folks">
...{text => str(text)}
type pair;
[@bs.get] external provider: pair => ReasonReact.reactClass = "Provider";
[@bs.get] external consumer: pair => ReasonReact.reactClass = "Consumer";
[@bs.module "React"] external createContext: 'a => pair = "";
module MakePair = (Config: {
type t;
let defaultValue: t;
}) => {
let _pair = createContext(Config.defaultValue);
module Provider = {
let make = (~value: Config.t, children) =>
~props={"value": value},
module Consumer = {
let make = (children: (Config.t) => ReasonReact.reactElement) =>
Copy link

KidkArolis commented Sep 8, 2018

I get this error:


Copy link

gaelollivier commented Nov 11, 2018 should probably be [@bs.module "react"], otherwise it seems react is loaded twice. Might be a webpack issue though.

Here's the warning I get:

There are multiple modules with names that only differ in casing.
This can lead to unexpected behavior when compiling on a filesystem with other case-semantic.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment