According to the documentation, this is a context file.
/** ContextProvider.re */
let themeContext = React.createContext("light");
include React.Context; // Adds the makeProps external
let make = React.Context.provider(themeContext);
But makeProps is not exported from this file as a result
Any chance of seeing an example where useReducer is sent down context?
My incomplete example looks something like this so far:
module TodoContext = {
let stateContext = React.createContext(Todo.initialState)
let dispatchContext = React.createContext()
module Provider = {
let stateProvider = React.Context.provider(stateContext)
let dispatchProvider = React.Context.provider(dispatchContext)
@react.component
let make = (~children) => {
let (state, dispatch) = React.useReducer(Todo.reducer, Todo.initialState)
let dispatchProviderComponent = React.createElement(
dispatchProvider,
{"value": dispatch, "children": children},
)
let stateProviderComponent = React.createElement(
stateProvider,
{"value": state, "children": children},
)
}
}
}
Some questions:
Read somewhere that it’s better to send state and dispatch down two separate providers for re-rendering performance reasons. Is this correct?
What value do I pass when creating the context for dispatch, and also for state? Is the let stateContext = React.createContext(Todo.initialState) correct?
How do I nest the dispatchProviderComponent and the stateProviderComponent for the return?
Apologies for the long question! Very new to React and Rescript Hope someone can help
This code in the docs should work with @rescript/react. The issue was that it was documented without being released. This has the advantage not to generate any additional runtime.