当前位置:网站首页>传递泛型给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-NSDictionary
7.联合索引(最左前缀原则)
FormData upload binary file, object, object array
flutter在导航栏处实现对两个列表的点击事件
PLSQL Developer安装和配置
(2022 Nioke Duo School 5) C-Bit Transmission (Thinking)
metabase访问adb mysql 如何控制会话时区??
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
理论问题与工程问题的差异在哪里?
静态路由综合实验
spark 读取本地文件
MySQL事务(transaction) (有这篇就足够了..)
UG NX二次开发(C#)-外部模式-导出dwg格式的文件
MySQL-Multiversion Concurrency Control
Inverter Phase Locking Principle and DSP Implementation
pnpm + workspace + changesets 构建你的 monorepo 工程
MySQL error 1055 solution: [Err] 1055 - Expression #1 of ORDER BY clause is not in GROUP BY clause and contains
OSPF 综合实验
Control 'ContentPlaceHolder1_ddlDepartment' of type 'DropDownList' must be placed inside a form tag with runat=server.
Ask a question, my Flinkcdc has run through, I can monitor the binlog of msql, and I can also send kafk









