Derived State: Fully uncontrolled component with a key
还没有人认领这个 Issue。
- 主要语言
- JavaScript
- 星标
- 11.8k
- 派生
- 7.9k
- 平均合并
- 1 天 11 小时
- 30 天内合并 PR
- 11
描述
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?
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
从链接的“ You Probably Don't Need Derived State”文章以及报告的访问 key 时出现的 PropTypes 警告开始。确定文档是否需要澄清带有 key 的完全非受控组件;完成标准是文章解释一种有效的缓解方法,或明确记录这一限制。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- javascript, react
- 领域
- documentation
- Issue 类型
- 文档
- 难度
- 3/5
- 预计耗时
- 1-2 天
- 活跃度
- 停滞
- 描述清晰度
- 需要澄清
- 新手友好度
- 25/100