以antd为例 React+Typescript 引入第三方UI库

本文 我们来说说 第三方UI库

其实应用市场上的 第三方UI库都是非常优秀的

那么 react 我们比较熟的肯定还是 antd 我们还是来用它作为演示

这边 我们先访问他的官网 https://3x.ant.design/index-cn

点击开始使用

在左侧 有一个 在 TypeScript 中使用

通过图标我们也可以看出 这个UI库与react的关系不一般

上面这种 快速创建一个项目的 就算了 不太适合我们的情况

我们看下面引入的方式

这里 我们还是用 npm的方式

打开我们的项目 终端输入

java 复制代码
npm install antd --save

这样 依赖包就进来了

然后 我们

javascript 复制代码
npm start

启动项目

这边也是没有任何问题

然后 我们按这个文档的案例 将自己的组件改一改

typescript 复制代码
import * as React from "react";
import Button from 'antd/es/button';

interface IProps {
}


export default class hello extends React.Component<IProps,any> {

    public readonly state: Readonly<any> = {
        data: []
    }
    
    public constructor(props:IProps){
        super(props);
    }

    public render() {
        return (
            <div>
              <Button type="primary">Button</Button>
            </div>
        )
    }
}

运行项目

按钮就出现了

然后 我们尝试一个其他组件

编写代码如下

typescript 复制代码
import * as React from "react";
import { Progress } from 'antd';

interface IProps {
}

export default class hello extends React.Component<IProps,any> {

    public readonly state: Readonly<any> = {
        data: []
    }
    
    public constructor(props:IProps){
        super(props);
    }

    public render() {
        return (
            <div>
                <Progress type="circle" percent={75} />
                <Progress type="circle" percent={70} status="exception" />
                <Progress type="circle" percent={100} />
            </div>
        )
    }
}

运行结果如下

相关推荐
德尔塔A3 小时前
中文全文检索加向量,我用 SQLite 做到零依赖
typescript
wflynn3 小时前
GitHub 今日推荐|rea:用 MCP 把反编译器和 AI agent 接到一起的逆向工具
typescript·开源·github·agent·agent-skills·binary-analysis
德尔塔A3 小时前
AI 改了 300KB 的文件,我让浏览器一屏都不多拿
typescript
德尔塔A3 小时前
给 Agent 写终端界面,我一个 UI 库都没装
typescript
德尔塔A3 小时前
同一条命令,在 Windows 上炸了三种方式
typescript
德尔塔A4 小时前
同一个会话,终端和浏览器同时开着会发生什么
typescript
咚咚咚小柒6 小时前
【前端】LangChain.js学习
前端·javascript·人工智能·typescript·langchain·vue·ai编程
螺丝钉tina12 小时前
[Playwright][01] 从 Puppeteer 到 Playwright:为什么选择 Playwright + TypeScript?
前端·javascript·typescript
喜欢吃豆12 小时前
我开源了 Agent UI Lab 用交互实验理解 AG-UI A2UI 与 MCP Apps
ui·开源·大模型·交互
染指11101 天前
158.Agent-LangGraph-子图(共享状态和不共享状态模式)
开发语言·人工智能·python·ui·agent·agents