React docs on "Building Your Own Hooks"
还没有人认领这个 Issue。
- 主要语言
- JavaScript
- 星标
- 11.8k
- 派生
- 7.9k
- 平均合并
- 1 天 11 小时
- 30 天内合并 PR
- 11
描述
Please provide guidance if returning elements (or ()=>elements) from custom hook is a good practice or not.
We have a PageLayout component like the following in our own app:
<PageLayout
topBarButtons={..}
onRender={..}
/>
We want to encapsulate topBarButtons and onRender logic within a custom hook, so that the hook is reusable and shippable without PageLayout. (topBarButtons and onRender will share some state, and useOurHook returns [topBarButtons, onRenderFunc]).
This works fine, if not perfect, for me. But since there are so few custom hook example that returns UI elements (or function that returns UI elements like onRender), the team have doubt about this pattern.
I know the doc has the following statement, but I think this is a very common scenario that deserves a sentence or two in the React docs.
"useYourImagination()
Custom Hooks offer the flexibility of sharing logic that wasn’t possible in React components before. You can write custom Hooks that cover a wide range of use cases like form handling, animation, declarative subscriptions, timers, and probably many more we haven’t considered."
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
从 "Building Your Own Hooks" 文档页面开始,查看其中现有的关于自定义 Hooks 的指导和示例。添加一段简洁的说明,解释返回元素或返回元素的函数是否是合适的模式,包括此处描述的共享状态场景;该页面应能回答团队的问题,而不需要了解此 issue 的应用程序特定上下文。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- javascript, react
- 领域
- documentation
- Issue 类型
- 文档
- 难度
- 2/5
- 预计耗时
- 1-3 小时
- 活跃度
- 停滞
- 描述清晰度
- 基本清楚
- 新手友好度
- 50/100