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.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Great article. Just a little question. Are we actually initializing user two times? Once in root and once in the context?
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
contextis a default value that will only be used if there is no matchingProviderin 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 inReasonhowever 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 itoptionand passNonein context andSome(computedValue)in the root.