contextTypeHandler
Finds legacy React contextTypes declarations and adds them to the
documentation under the context field.
It uses the same PropTypes parsing logic as
propTypeHandler, but writes descriptors to
context instead of props.
Examples
When the contextTypeHandler is active either of these components will result
in the output below.
component.tsx
import PropTypes from 'prop-types';
class MyComponent extends React.Component {
static contextTypes = {
theme: PropTypes.string,
disabled: PropTypes.bool.isRequired,
};
render() {
return <div />;
}
}component.tsx
import PropTypes from 'prop-types';
function MyComponent() {
return <div />;
}
MyComponent.contextTypes = {
theme: PropTypes.string,
disabled: PropTypes.bool.isRequired,
};Output
JSON
[
{
"context": {
"theme": {
"type": {
"name": "string"
},
"required": false
},
"disabled": {
"type": {
"name": "bool"
},
"required": true
}
}
}
]Source
Last updated on