当前位置:网站首页>传递泛型给JSX元素
传递泛型给JSX元素
2022-08-02 07:31:00 【Pandy : )】
将泛型传给 JSX 元素语法:
<Component<GenericType> />
挺简单的,刚好最近写的一个组件使用到了泛型,主要是给 Props 使用,可以看看这个例子:
- 先定义 Props 接口:
interface Props<LabelType extends string = string> extends CommonProps {
tabItems: Array<{
label: LabelType;
}>;
selectedTab: LabelType;
setSelectedTab: Dispatch<SetStateAction<LabelType>>;
}
- 再定义组件函数:
export default function SlideTabs<LabelType extends string = string>({
tabItems,
selectedTab,
setSelectedTab,
}: Props<LabelType>): React.ReactElement {
//...
}
- 接着在引用组件上传递泛型:
<SlideTabs<ResourceType>
{...{ tabItems, selectedTab, setSelectedTab }}
/>
REFERENCE
边栏推荐
- 7.联合索引(最左前缀原则)
- 典型的一次IO的两个阶段是什么?阻塞、非阻塞、同步、异步
- Inverter insulation detection detection function and software implementation
- (2022 Niu Ke Duo School 5) B-Watches (two points)
- PanGu-Coder:函数级的代码生成模型
- uniapp 禁止默认返回事件
- HCIP 第八天
- (2022 Nioke Duo School 5) C-Bit Transmission (Thinking)
- postgres groupby 合并字符串
- Debian 10 dhcp relay (dhcp 中继) dhcp 固定分配
猜你喜欢

MySQL - Detailed Explanation of Database Transactions
![MySQL报错1055解决办法:[Err] 1055 - Expression #1 of ORDER BY clause is not in GROUP BY clause and contains](/img/aa/ab58ec47bb96df803dbc6a8ff6dde3.png)
MySQL报错1055解决办法:[Err] 1055 - Expression #1 of ORDER BY clause is not in GROUP BY clause and contains
![[Unity3D] Beginner Encryption Skills (Anti-Cracking)](/img/07/4a0731dd66b058c07d6240ffd36eea.png)
[Unity3D] Beginner Encryption Skills (Anti-Cracking)

MySQL-Execution Process + Cache + Storage Engine

Neural network

Hack The Box - File Transfers Module详细讲解中文教程

论文理解:“Cross-Scale Residual Network: A GeneralFramework for Image Super-Resolution,Denoising, and “

HCIP 第十一天

MySQL-FlinkCDC-Hudi enters the lake in real time

MySQL常见索引类型
随机推荐
Introduction to mysql operation (4) ----- data sorting (ascending, descending, multi-field sorting)
spark read local file
机器学习笔记--数学库
MySQL常见索引类型
flutter 自己写一个组件
CollectionUtil: a collection of functional style tool
OSPF 综合实验
Probability Theory and Mathematical Statistics
MySQL-Execution Process + Cache + Storage Engine
59: Chapter 5: Develop admin management services: 12: MongoDB usage scenarios; (non-core data, non-core data with a relatively large amount of data, small private files such as face photos;)
MySQL之创建表的基本操作
7.联合索引(最左前缀原则)
MySQL事务隔离级别详解
Kind of weird!Access the destination URL, the host can container but not
典型的一次IO的两个阶段是什么?阻塞、非阻塞、同步、异步
spark architecture
HCIP 第九天
用户身份标识与账号体系实践
通过建立新的SaaS业务来推动增长的六种方法
WebForm DropDownList bind year and month respectively