question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Does not work with `class` Components

See original GitHub issue

I am trying to extract prop-types info from a component in storybook. I am using the default babel-plugin-react-docgen that comes baked in to @storybook/react@4.1.7 which is at version 2.0.0 It looks like that uses react-docgen@3.0.0-rc.1

When I console.log(Component.__docgenInfo) in a story file for a Component that is defined with class:

class Component extends React.Component {...}

When I do the same thing in a story file for a Component that is defined with function, everything seems to work as expected.

function Component() {...}

However, if I use react-docgen cli to generate the docgen info, I get all of the expected info from the class based Component.

npx react-docgen ./src/components/Component.jsx

Any help would be appreciated on why this might not be working.

I tried to just generate/parse the react docgen in the story file without the babel plugin, but I can’t seem to get the full untranspile source from the story file.


Here is my .babelrc

{
  "presets": [
    [
      "@babel/preset-env",
      {
        "useBuiltIns": "usage"
      }
    ],
    "@babel/preset-react"
  ],
  "plugins": [
    "transform-class-properties",
    [
      "module-resolver",
      {
        "root": ["."],
        "alias": {
          "storybook": ["./.storybook"]
        }
      }
    ]
  ]
}
  • babel-plugin-react-docgen is coming from storybook, but I did try to add it with a custom name, still no luck.
  • I tried removing transform-class-properties to no avail

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:5
  • Comments:12 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
NuclleaRcommented, Mar 18, 2019

Have the same issue. Didn’t use any .babelrc. just CRA

1reaction
supersnagercommented, Jul 27, 2020

Still does not work for me. I’m using v4.0.1.

Webpack custom configuration:

webpackFinal: async (config, { configType }) => {
    
    config.module.rules.push({
      include: [
        path.resolve(__dirname, '../node_modules/some_package'),
      ],
      test: /\.js$/,
      use: [
        {
          loader: "babel-loader",
          options: {
            plugins:[
              [
                "babel-plugin-react-docgen",
                { DOC_GEN_COLLECTION_NAME: "STORYBOOK_REACT_CLASSES" },                
              ]
            ]
          }
        }
      ]
    });
    
    return config;
    
  }

I think that this issue should be reopened.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Class based component is not working as expected in ...
I am trying to show the content of my class-based component in part of the functional component but it is not working. class-based...
Read more >
Does not work with `class` Components · Issue #66 - GitHub
I am trying to extract prop-types info from a component in storybook. I am using the default babel-plugin-react-docgen that comes baked in ...
Read more >
React Class Components - W3Schools
Before React 16.8, Class components were the only way to track state and lifecycle on a React component. Function components were considered "state-less"....
Read more >
From class components to React Hooks - CircleCI
Hooks offer more flexibility and they can be reused, especially custom ones in multiple components. With Hooks, you do not need to use...
Read more >
Error Boundaries - React
A class component becomes an error boundary if it defines either (or both) of the lifecycle methods static getDerivedStateFromError() or componentDidCatch() .
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found