react中动态渲染antd的icon

本文介绍了一个React函数组件,它利用@ant-design/icons库中的HomeOutlined图标,展示了一个包含多种技术分类的左侧导航栏,如前端、后端、移动应用等。
摘要由CSDN通过智能技术生成
import * as Icon from "@ant-design/icons";
import React from "react";
function leftTab() {
  const iconToElement = (name: string) =>
    React.createElement(Icon && (Icon as any)[name], {
      style: { fontSize: "17px" },
    });
  const tabList = [
    {
      icon: "HomeOutlined",
      name: "大模型子站",
    },
    {
      icon: "HomeOutlined",
      name: "关注",
    },
    {
      icon: "HomeOutlined",
      name: "综合",
    },
    {
      icon: "HomeOutlined",
      name: "后端",
    },
    {
      icon: "HomeOutlined",
      name: "前端",
    },
    {
      icon: "HomeOutlined",
      name: "Android",
    },
    {
      icon: "HomeOutlined",
      name: "iOS",
    },
    {
      icon: "HomeOutlined",
      name: "人工智能",
    },
    {
      icon: "HomeOutlined",
      name: "开发工具",
    },
    {
      icon: "HomeOutlined",
      name: "代码人生",
    },
    {
      icon: "HomeOutlined",
      name: "阅读",
    },
    {
      icon: "HomeOutlined",
      name: "排行榜",
    },
  ];
  return (
    <>
      <div className="tabs_all_content">
        {tabList.map((item, index) => {
          return (
            <div className="tabs_items" key={index}>
              <div className="icon">{iconToElement(item.icon)}</div>
              <div className="left_name">{item.name}</div>
            </div>
          );
        })}
      </div>
    </>
  );
}

export default leftTab;

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值