DEV Community

loading...

Discussion on: ReasonReact context explained in action

Collapse
margaretkrutikova profile image
Margarita Krutikova Author

Thank you for your feedback!
That's a great question, I haven't really thought about it myself. It appears that the value passed inside context is a default value that will only be used if there is no matching Provider in the tree, just found it in the react docs. Could be useful for testing components in isolation.

I guess in the Javascript world one could simply omit passing a value in the context (resulting in undefined), here in Reason however we must pass a value of the correct type (context value). If it is important to not compute the initial value two times (due to some heavy things going on there), one could make it option and pass None in context and Some(computedValue) in the root.