When using flowtype to define a prop in the context in this way
// @flow
type MyType = Object;
class CustomView extends React.Component {
static childContextTypes = {
someProp: MyType
}
getChildContext() {
return {
someProp: this.props.someProp
};
}
}
I got the following error:
CustomView: type specification of child context
someProps
is invalid; the type checker function must returnnull
or anError
but returned a object. You may have forgotten to pass an argument to the type checker creator (arrayOf, instanceOf, objectOf, oneOf, oneOfType, and shape all require an argument).
So I am forced to use propTypes.object
instead of Object
.
No, you cannot use a Flow type as a type in childContextTypes
. The reason is that childContextTypes
is checked at runtime, and Flow types do not have any runtime representation. Therefore the "types" in childContextTypes
must be values - specifically the values provided by the prop-types npm package.
The use of MyType
in your example is actually a syntax error: MyType
appears in the position of an object property value which must be a value, not a type.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With