Args: Support dynamic PropTypes
See original GitHub issueWhat
Inspect a component’s runtime propTypes to determine what to show in its ArgsTable
Why
Currently, Storybook extracts ArgTypes for JS React components using react-docgen. React-docgen performs a file-by-file static analysis of your components. This is efficient, generally well-supported, and is able to pull out things like JSDoc comments from the source code. However, it has a couple issues:
- PropTypes can be functions, and these are difficult to analyze statically
- PropTypes can be defined in separate files, and these are currently unsupported
By inspecting the runtime propTypes of a component and using this as a fallback (or combining it with the docgen?) we can overcome some of these problems.
We chose not to do this in the original implementation because it can easily obscure issues in the docgen setup. However, in practice many users want it, so we should consider adding this as part of React’s ArgType extraction.
User story
As a component developer,
I want Storybook to automatically dynamic PropTypes
So that I don't need to manually document them
Related issues
Issue Analytics
- State:
- Created 3 years ago
- Reactions:53
- Comments:17 (4 by maintainers)

Top Related StackOverflow Question
We tried setting up propTypes in a separate file and import it into the component file. But was disappointed as it does not work. 😦
Something like,
Bumping this issue – generating dynamic PropType lists from imported enums would be a really valuable feature. Are there any plans to tackle this in 2022?