I would like to define default values for an object passed to the React.createContext
function:
// TreeContext.res
let context = React.createContext({
"selectedId": "", // I would like this to be optional
"theme": "dark"
})
let makeProps = (~value, ~children, ()) => {
"value": value,
"children": children,
};
let make = React.Context.provider(context);
Of course, the following code:
// Tree.res
@react.component
let make = () =>{
<TreeContext value={ "theme": "light" }>
{React.string("Hi there!")}
</TreeContext>
}
throws an error:
This has type: {"theme": string}
Somewhere wanted: {"selectedId": string}
The second object type has no method theme