react-docgen icon indicating copy to clipboard operation
react-docgen copied to clipboard

react-docgen is not compatible with react-like libraries

Open Chaptykov opened this issue 9 years ago • 3 comments

There are some react-like libraries such as react-lite, preact-compat and other which use API of React for components including PropTypes. All react-docgen methods work well with these libraries. But [this module](react-docgen disables work with react-like libraries) disallows using it.

I have a preact-compat component:

import { h, Component, PropTypes } from 'preact-compat';

export default class MyComponent extends Component {
  render() {
    return <div>{this.props.children}</div>;
  }
}

MyComponent.propTypes = {
  myProp: PropTypes.func
};

Actual react-docgen returns this value for type of myProp:

{
  name: 'custom',
  raw: 'PropTypes.func'
}

If I add preact-compat to whitelist react-docgen returns expected result:

{
  type: 'func'
}

Chaptykov avatar Jul 06 '16 09:07 Chaptykov

We could add a configuration option that lets you specify the module name(s) to validate against. Maybe we should add support for configuration files in the future if the configuration options keep increasing.

fkling avatar Aug 02 '16 16:08 fkling

@Chaptykov , I realize this is an old issue, but where is the whitelist you mentioned? I see reactModules in utils/isReactModuleName, but adding preact, preact-compat, and/or preact/compat to that array does not get the correct prop types to be created for me. I still see name: 'custom', as you described.

binomialstew avatar May 12 '22 15:05 binomialstew

It turns out, the custom name in my case was not due to Preact but instead because PropTypes is not imported into each component.

binomialstew avatar May 18 '22 16:05 binomialstew