Addon-Docs: Props table won't be generated for TypeScript types if forwardRef used with the default export
See original GitHub issueDescribe the bug If forwardRef used without named export and with only default one, then no props table will be generated.
For example, this:
Button.tsx
import React, { forwardRef } from 'react';
interface ButtonProps {
/**
* Sets the button size.
*/
variant?: 'small' | 'large';
/**
* Disables the button.
*/
disabled?: boolean;
}
const Button = forwardRef<HTMLButtonElement, ButtonProps>(
({ disabled = false, variant = 'small', children }, ref) => (
<button disabled={disabled} ref={ref}>
{children} {variant}
</button>
),
);
export default Button;
Button.stories.tsx
import React, { FC } from 'react';
import Button from './Button';
export default { title: 'Button', component: Button };
export const Default: FC = () => <Button>I'm a button!</Button>;
Will lead to this result:
But if I add export, a props table will be generated. No need to change import from default to named, jus add export.
export const Button = forwardRef<HTMLButtonElement, ButtonProps>(
({ disabled = false, variant = 'small', children }, ref) => (
<button disabled={disabled} ref={ref}>
{children} {variant}
</button>
),
);
Expected behavior A props table should be generated
Packages
{
"@storybook/addon-actions": "^5.3.5",
"@storybook/addon-docs": "^5.3.5",
"@storybook/addon-links": "^5.3.5",
"@storybook/addons": "^5.3.5",
"@storybook/preset-create-react-app": "^1.5.1",
"@storybook/preset-typescript": "^1.2.0",
"@storybook/react": "^5.3.5"
}
main.js
module.exports = {
stories: ['../src/**/*.stories.(tsx|mdx)'],
addons: [
{
name: '@storybook/preset-create-react-app',
options: {
tsDocgenLoaderOptions: {},
},
},
{
name: '@storybook/addon-docs',
options: {
configureJSX: true,
},
},
],
};
Issue Analytics
- State:
- Created 4 years ago
- Comments:15 (3 by maintainers)
Top Results From Across the Web
argTypes table is not generated for components with React ...
The problem is that if you have a React component wrapped in React.forwardRef and with index type in its interface, the arcTypes table...
Read more >Guides:TypeScript - SolidJS · Reactive Javascript Library
Solid is written in TypeScript, so everything is typed out of the box. The API documentation details the types for all API calls,...
Read more >react-dropzone
Simple React hook to create a HTML5-compliant drag'n'drop zone for files. Documentation and examples at https://react-dropzone.js.org.
Read more >Error when trying to inject a service into an angular ...
Adding @Inject(forwardRef(() => MobileService)) to the parameter of the constructor in the original question's source code will fix the problem.
Read more >material-ui/core/CHANGELOG.md - UNPKG
130, - [docs] Use codesandbox deploy for demos created from deploy previews ... 268, - [docs] Correct the name of a prop in...
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 FreeTop 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
Top GitHub Comments
Hi, You are missing the export keyword before the Component’s name. You have to export const {Component} too, as react-docgen-typescript-loader or react-docgen-loader has not added support for forwardRef’s yet.
If someone got here in search of why props aren’t generated as it did for me, try instead of writing
Do it this way: