ionic-team / ionic-team/ionic-framework
feat: react, update useIonModal signature to accept all parameters in one object
- 主要语言
- TypeScript
- 星标
- 52.7k
- 派生
- 13.3k
- 平均合并
- 1 天 14 小时
- 30 天内合并 PR
- 50
描述
### Prerequisites
- [X] I have read the [Contributing Guidelines](https://github.com/ionic-team/ionic-framework/blob/main/.github/CONTRIBUTING.md#creating-an-issue).
- [X] I agree to follow the [Code of Conduct](https://ionicframework.com/code-of-conduct).
- [X] I have searched for [existing issues](https://github.com/ionic-team/ionic-framework/issues) that already include this feature request, without success.
### Describe the Feature Request
Currently, the `useIonModal` hook has this signature:
```
const [present, dismiss] = useIonModal(component: ReactComponentOrElement, componentProps?: any);
```
A common React paradigm is to enclose all input parameters into one object. This is primarily done to destructure the bits of input/output that you need at any moment in time:
```
const { getAccount } = useAccountsAPI();
const MyComponent = ({ myProp1, myProp2 }) =>
```
### Describe the Use Case
It's also become a pattern developers use as context clues to figure out what something does.
This can make the current `useIonModal()` signature confusing:
```
const [present, dismiss] = useIonModal(MyComponent, { myProp1, myProp2, onDismiss: dismiss() });
```
### Describe Preferred Solution
Adjusting the signature could improve the ergonomics of the hook:
```
const [present, dismiss] = useIonModal({ component: ReactComponentOrElement, props?: any);
```
Taken further, we can use TypeScript's generics to type the component's props:
```
const [present, dismiss] = useIonModal({ component: ReactComponentOrElement, props: T});
```
### Describe Alternatives
_No response_
### Related Code
_No response_
### Additional Information
_No response_
贡献指南
调研方向
在仓库中搜索 useIonModal hook 的使用情况及其当前调用位置,以了解现有签名和使用模式。检查 component 和 props 输入的类型定义及测试方式;完成的标准是,提议的基于对象的 API 已按照一致的方式实现,并采用适当的泛型 props 类型定义,同时现有用法仍得到处理。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- react, typescript
- 领域
- frontend
- Issue 类型
- 功能
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 活跃度
- 停滞
- 描述清晰度
- 基本清楚
- 新手友好度
- 35/100