Skip to content

Commit

Permalink
docs(context-mixins): binding to external Context
Browse files Browse the repository at this point in the history
  • Loading branch information
alavkx committed Nov 12, 2019
1 parent 80e02f7 commit 73a064f
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions docs/context-mixins.md
Expand Up @@ -45,5 +45,29 @@ let make = () => {
}
```

## Binding to an external Context

Binding to a Context defined in a JS file holds no surprises.

```js
/** ComponentThatDefinesTheContext.re */
export const JwtContext = React.createContext("light");
```

```reason
/** ComponentToConsumeTheContext.re */
module JwtContext = {
[@bs.module "ComponentThatDefinesTheContext"]
external make: React.Context.t('context) = "JwtContext";
};
[@react.component]
let make = () => {
let theme = React.useContext(ThemeContext.make);
<h1>theme->React.string</h1>
}
```

## Mixins
ReasonReact doesn't support ReactJS mixins. Composing normal functions is a good alternative.

0 comments on commit 73a064f

Please sign in to comment.