From 73a064f21d55e03491b6cde3cf8e73835c036d29 Mon Sep 17 00:00:00 2001 From: Alec Date: Tue, 12 Nov 2019 11:26:41 -0500 Subject: [PATCH] docs(context-mixins): binding to external Context --- docs/context-mixins.md | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/docs/context-mixins.md b/docs/context-mixins.md index 25ad79db8..19f3f8d38 100644 --- a/docs/context-mixins.md +++ b/docs/context-mixins.md @@ -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); + +

theme->React.string

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