hipstersmoothie / react-docgen-typescript-plugin

A webpack plugin to inject react typescript docgen information
MIT License
68 stars 28 forks source link

Generated code doesn't work with forwardedRef #85

Open meriouma opened 1 year ago

meriouma commented 1 year ago

I have a component that is exported this way : export const IconButton = forwardRef<HTMLButtonElement, IconButtonProps>(...) When I look into the code generated by webpack, it looks like this :

exports.IconButton = (0, react_1.forwardRef)((_a,ref)=>{...});
exports.IconButton.displayName = 'IconButton';

try {
    // @ts-ignore
    IconButton.displayName = "IconButton";
    // @ts-ignore
    IconButton.__docgenInfo = {
        ...
    };
    // @ts-ignore
    if (typeof STORYBOOK_REACT_CLASSES !== "undefined")
        // @ts-ignore
        STORYBOOK_REACT_CLASSES["src/components/buttons/icon-button.tsx#IconButton"] = {
            docgenInfo: IconButton.__docgenInfo,
            name: "IconButton",
            path: "src/components/buttons/icon-button.tsx#IconButton"
        };
} catch (__react_docgen_typescript_loader_error) {}

The generated code doesn't include the exports. prefix, which ends up throwing this error : ReferenceError: IconButton is not defined (logged __react_docgen_typescript_loader_error);

hipstersmoothie commented 1 year ago

Interesting. I don't have time to look into this myself but would merge a PR that fixes it!