-
-
Notifications
You must be signed in to change notification settings - Fork 9.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Bug]: DefaultProps not being picked up with auto-docs in certain cases #30427
Comments
** Disclaimer** This information might be inaccurate, due to it being generated automatically To fix this, you would need to either:
const Component = ({ color = 'red', size = '10px', ...otherProps }) => {}
interface Props {
color?: string;
size?: string;
}
const defaultProps = {
color: 'red',
size: '10px'
} as const;
const Component = (props: Props = defaultProps) => {} The underlying issue is in react-docgen-typescript's prop detection logic which primarily looks at TypeScript types and parameter-level defaults rather than runtime assignments.
|
Hi @tourshi Have you tried |
Hi @tourshi I looked deeper at your issue and your provided example is not supposed to work. Default property values are only recognized when assigned in the arguments section of a function. Tools like This is just a natural limitation which will very likely not be supported by |
Describe the bug
Hi, with React 19 being stable now and defaultProps is deprecated. We've migrated our components to use ES6 defaults instead. However the storybook docs (react-docgen-typescript?) is not picking up the default props in certain cases.
For example. If I destructure the props in the component args it works, but if I destructure the props in the function body, it doesn't work.
const Component = ({ color = 'red', size = '10px', ...otherProps}) => ...
this works, butconst Component = (props) => { const { color = 'red', size = '10px', ...otherProps } = props; }
doesn't work.I know the manual alternative is to specify these defaults manually but are there any plans to have the docs plugin pick up on these defaults?
I'm asking because its not ideal to have two sources of truth for defaults, one in the component and one for the arg types. Also in my specific case we have a component library so there are hundreds of components to add argTypes for.
Thank you
Reproduction link
https://stackblitz.com/edit/github-nu39kd6h?file=src%2Fstories%2FButton.tsx
Reproduction steps
System
Additional context
No response
The text was updated successfully, but these errors were encountered: