reactjs / reactjs/react-docgen
[Typescript] Default props from defaults when destructuring
Open
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 3.8k
- Forks
- 316
- Avg merge
- 5h 7m
- Merged PRs (30d)
- 4
Description
The defaults work fine from the static .defaultProps property like ...
interface Props {
foo?: string;
}
const Test: React.SFC<Props> = (props: Props) => {
const { foo, ...rest } = props;
return (
<div { ...rest } />
);
}
Test.defaultProps = {
foo: 'bar',
};
export default Test;
I'm wondering if you think it would be possible to get default prop values from the defaults when destructuring during the render? like ...
interface Props {
foo?: string;
}
const Test: React.SFC<Props> = (props: Props) => {
const { foo = 'bar', ...rest } = props;
return (
<div { ...rest } />
);
};
export default Test;
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.
Research direction
No files, tests, or entry points are named in the issue. Start by locating the TypeScript and React prop/defaultProps handling, then determine whether destructuring can use defaults from static defaultProps; done means the documented example behaves as requested and is covered by a test.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- react, typescript
- Domain
- documentation, tooling
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 30/100