No suitable component definition found for higher-order component
See original GitHub issuereact-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.
Issue Analytics
- State:
- Created 5 years ago
- Reactions:10
- Comments:5 (2 by maintainers)
Top Results From Across the Web
No suitable component definition found for ... - Bountysource
react-docgen can't find a component definition when the component is defined as a higher-order component: import React from 'react'; ...
Read more >ESLint: Component definition is missing displayName (react ...
I tried this in a different context, where my code is a method of a non-React class (does not extend Component). Firstly I...
Read more >Higher-Order Components - React
A higher-order component (HOC) is an advanced technique in React for reusing component logic. HOCs are not part of the React API, per...
Read more >Understanding React Higher-Order Components by Example
Higher-order component considerations · A HOC should be a pure function with no side-effects. · Do not use HOC's in the render method...
Read more >React Higher Order Components in depth | by franleplant
Component being returned. The “wraps” part of the definition is intentionally vague because it can mean one of two things: Props Proxy: The...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
It would be helpful for “react-docgen to pickup the component returned by wrap” IMO
I managed to find a workaround that works for my components at least by hacking at the findExportedComponentDefinition resolver so it just returns whatever is exported without trying to resolve it to a component.
It works with my component in the form:
To use it, apply the patch to https://github.com/reactjs/react-docgen/blob/v5.4.0/src/resolver/findExportedComponentDefinition.js