Derived State: Fully uncontrolled component with a key
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 11.8k
- Forks
- 7.9k
- Avg merge
- 1d 11h
- Merged PRs (30d)
- 11
Description
Hi,
In the article You Probably Don't Need Derived State, one of the recommended ways to avoid deriving state from props, is to have "Fully uncontrolled component with a key".
However, there is no way to actually force the user to provide a 'key' property to the component, since declaring it in propTypes as "key: PropTypes.any.isRequired" won't work, because it's value is always 'undefined', which leads to a warning message:
Warning: MyComponent:
keyis not a prop. Trying to access it will result inundefinedbeing returned. If you need to access the same value within the child component, you should pass it as a different prop.
And without declaring the 'key' prop type, we cannot assume, that the user will use the component in a proper manner.
How to mitigate this?
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
Start with the linked “You Probably Don't Need Derived State” article and the reported PropTypes warning about accessing key. Determine whether the documentation needs clarification about fully uncontrolled components with a key; done means the article explains a valid mitigation or explicitly documents the limitation.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, react
- Domain
- documentation
- Issue type
- Documentation
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100