当前位置:网站首页>传递泛型给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
边栏推荐
- 理论问题与工程问题的差异在哪里?
- OC-NSString
- Splunk Filed extraction field interception
- LeetCode 2312. Sell Wood Blocks
- Debian 10 dhcp relay (dhcp 中继) dhcp 固定分配
- Comprehensive experiment of MPLS and BGP
- Enterprise training and reproduction guidebook - training and reasoning of the OpenPose model based on Huawei ModelArts platform, realizing the recognition of two behaviors of climbing and climbing ov
- 5分钟搞懂MySQL - 行转列
- Please tell me, how to write Flink SQL and JDBC sink into mysql library and want to create an auto-incrementing primary key
- 原型模式
猜你喜欢
随机推荐
.NET静态代码织入——肉夹馍(Rougamo) 发布1.1.0
MySQL - slow query log
MySQL-执行流程+缓存+存储引擎
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;)
@FeignClient configuration参数配置
MySQL - Index Optimization and Query Optimization
理论问题与工程问题的差异在哪里?
MPLS和BGP的综合实验
Azure Synapse Analytics上创建用户并赋予权限
MySQL batch update
MySQL-锁机制
MySQL database design specification
uni.navigateBack 中的坑
Thesis understanding: "Cross-Scale Residual Network: A GeneralFramework for Image Super-Resolution, Denoising, and "
MySQL之创建表的基本操作
Mysql error 2003 solution Can 't connect to Mysql server on' localhost '(10061).
Appium 滑动问题
The best interests of buying and selling stocks with handling fees [What is missing in the definition of DP status?]
MySQL事务(transaction) (有这篇就足够了..)
OC-NSString








