当前位置:网站首页>传递泛型给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
边栏推荐
- I.MX6U-ALPHA开发板(定时器按键消抖)
- HCIP 第六天
- MySQL-执行流程+缓存+存储引擎
- 牛客2022 暑期多校4 D Jobs (Easy Version)(递推优化策略)
- MySQL error 1055 solution: [Err] 1055 - Expression #1 of ORDER BY clause is not in GROUP BY clause and contains
- Splunk Filed extraction field interception
- flutter在导航栏处实现对两个列表的点击事件
- Debian 10 dhcp relay (dhcp 中继) dhcp 固定分配
- [Unity3D] Beginner Encryption Skills (Anti-Cracking)
- 原型模式
猜你喜欢

HCIP 第八天

Install Metasploitable2 on VMware

Buried development process

redis-高级篇

Fatal error compiling: 无效的目标发行版: 11

flutter 自己写一个组件

Metasploit(MSF)基础超级详细版

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

(2022 Niu Ke Duo School 5) B-Watches (two points)
![MySQL error 1055 solution: [Err] 1055 - Expression #1 of ORDER BY clause is not in GROUP BY clause and contains](/img/aa/ab58ec47bb96df803dbc6a8ff6dde3.png)
MySQL error 1055 solution: [Err] 1055 - Expression #1 of ORDER BY clause is not in GROUP BY clause and contains
随机推荐
HCIP 第十二天
基本SQL语句(一篇就够了)
研发创新编码器霍尔板,引领企业高质量发展
7.联合索引(最左前缀原则)
(2022 Niu Ke Duo School 5) D-Birds in the tree (tree DP)
理论问题与工程问题的差异在哪里?
Kind of weird!Access the destination URL, the host can container but not
HCIP 第十天
2022年防止网络攻击的15个网络安全实践,你学会了吗?
Comprehensive experiment of MPLS and BGP
Conditional constructor ~wapper
OC-error prompt
MySQL - locking mechanism
数据中台:始于阿里,兴于DaaS
MySQL - Detailed Explanation of Database Transactions
WebGPU 导入[2] - 核心概念与重要机制解读
sql创建表格 如图 运行完提示invalid table name 是什么原因
HCIP第三天
playwright 爬虫使用
MySQL之创建表的基本操作