Support for documenting component props in the component docBlock
Nobody has claimed this yet.
Assessment
- Difficulty
- 5/5
- Estimated time
- Over a week
- Newbie friendliness
- 30/100
- Issue type
- Feature
- Clarity
- Needs clarification
- Activity status
- Stale
- Tech stack
- javascript, react
- Domain
- documentation
Research direction
Start by reviewing how the component docBlock, JSDoc tags, and propTypes property comments are currently interpreted. Compare the proposed @prop and @react.prop forms, including nested names such as foobar.foo, and define the supported syntax and generated documentation before implementing and testing the feature.
Written by the indexing model from the issue text.
Description
As of now, the docblock describing a property must be directly above where the property field is defined. As such
class MyComponent {
static propTypes = {
/**
* Does things that only a foo can
*/
foo: PropTypes.string,
/**
* Does things that only a bar can
*/
bar: PropTypes.string,
}
}
Which is a fine solution, but can get very bloated when you start having more props.
class MyComponent {
static propTypes = {
/**
* Does things that only a foo can
*/
foo: PropTypes.string,
/**
* Does things that only a bar can
*/
bar: PropTypes.string,
/**
* Does things that only a foobar can
*/
foobar: PropTypes.shape({
/**
* Does things that only a foo can
*/
foo: PropTypes.string,
/**
* Does things that only a bar can
*/
bar: PropTypes.string,
}),
/**
* Does things that only a foobar can
*/
foobar: PropTypes.shape({
/**
* Does things that only a foo can
*/
foo: PropTypes.string,
/**
* Does things that only a bar can
*/
bar: PropTypes.string,
}),
}
}
You can online the comments, but with some descriptions being long enough to require being on two line, it ends up looking messy in my opinion.
class MyComponent {
static propTypes = {
/** Does things that only a foo can*/
foo: PropTypes.string,
/** Does things that only a bar can */
bar: PropTypes.string,
/** Does things that only a foobar can */
foobar: PropTypes.shape({
/**
* Some properties will have a longer description that require them to be
* on multiple lines
*/
foo: PropTypes.string,
/** Does things that only a bar can */
bar: PropTypes.string,
}),
/** Does things that only a foobar can */
foobar: PropTypes.shape({
/** Does things only a foo can */
foo: PropTypes.string,
/** Does things that only a bar can */
bar: PropTypes.string,
}),
}
}
What I'm proposing is a JSDoc like tag that allows you to descibe the props for a component in the docblock for the component itself, somthing like:
/**
* @prop foo - Does things that only a foo can
* @prop bar - Does things that only a bar can
* @prop foobar - Does things that only a foobar can
* @prop foobar.foo - Some properties will have a longer description that require them to be on multiple lines
* @prop foobar.bar - Does things that only a bar can
* @prop foobar - Does things that only a foobar can
* @prop foobar.foo - Does things that only a foo can
* @prop foobar.bar - Does things that only a bar can
*/
class MyComponent {
static propTypes = {
foo: PropTypes.string,
bar: PropTypes.string,
foobar: PropTypes.shape({
foo: PropTypes.string,
bar: PropTypes.string,
}),
foobar: PropTypes.shape({
foo: PropTypes.string,
bar: PropTypes.string,
}),
}
}
Seing as prop is an existing JSDoc tag, it might be an idea to prefix it with something. Perhaps react., so
/**
* @react.prop name - description
*/
Is this something that would be worth looking into?
- Dominant language
- TypeScript
- Stars
- 3.8k
- Forks
- 316
- Avg merge
- 5h 7m
- Merged PRs (30d)
- 4
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from reactjs/react-docgen
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
reactjs/react-docgen#1102 ·
-
Difficulty 3/5 1-2 days Newbie friendliness 58/100
reactjs/react-docgen#1134 ·
-
Typescript Status Open
Difficulty 5/5 Over a week Newbie friendliness 20/100
reactjs/react-docgen#1005 · 4 reactions ·
-
Difficulty 3/5 1-2 days Newbie friendliness 48/100
reactjs/react-docgen#997 ·
-
Difficulty 3/5 1-2 days Newbie friendliness 42/100
reactjs/react-docgen#994 · 1 comment ·
All issues in reactjs/react-docgen
Similar issues
-
clawsweeper:fix-shape-clear clawsweeper:queueable-fix clawsweeper:source-repro impact:ux-friction issue-rating: 🦞 diamond lobster no-stale P3
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
community first-timers-only good first issue hacktoberfest help wanted low hanging fruit up-for-grabs
Difficulty 1/5 Under an hour Newbie friendliness 76/100
-
code-quality refactoring
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
github/gh-aw-firewall#8816 ·
-
integration:quickjs org:external priority:backlog topic:code-interpreter topic:middleware type:feature
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
langchain-ai/deepagents#6450 ·
-
Difficulty 1/5 Under an hour Newbie friendliness 88/100
vercel/react-tweet#225 ·