Skip to content

No suitable component definition found for higher-order component #288

@emccorson

Description

@emccorson

react-docgen can't find a component definition when the component is defined as a higher-order component:

import React from 'react';

const wrap = (CustomElement) => (props) =>
    <CustomElement { ...props } >{ props.children }</CustomElement>

const Test = wrap('custom-element');

export default Test;
> node_modules/.bin/react-docgen src/components/Test.jsx

Error with path "src/components/Test.jsx": Error: No suitable component definition found.
Error: No suitable component definition found.
    at parse (/private/tmp/test/bindings/react/node_modules/react-docgen/dist/parse.js:84:9)
    at Object.defaultParse [as parse] (/private/tmp/test/bindings/react/node_modules/react-docgen/dist/main.js:66:30)
    at parse (/private/tmp/test/bindings/react/node_modules/react-docgen/bin/react-docgen.js:103:17)
    at /private/tmp/test/bindings/react/node_modules/react-docgen/bin/react-docgen.js:204:30
    at FSReqWrap.oncomplete (fs.js:153:5)

If I apply the function myself, react-docgen works as expected:

const Test = (props) =>
    <custom-element { ...props } >{ props.children }</custom-element>
> node_modules/.bin/react-docgen src/components/Test.jsx

{"description":"","displayName":"Test","methods":[]}

Tested with react-docgen@2.21.0.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions