以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>
        )
    }
}

运行结果如下

相关推荐
qq_4260039635 分钟前
【UI自动化测试】UI自动化报错解决方案
运维·ui·自动化
红尘散仙1 小时前
TypeScript WIT Guest:类型约束与 ComponentizeJS 工程化
rust·typescript·webassembly
Oll Correct1 小时前
Adobe illustrator 案例九:百宝箱图标绘制
笔记·ui·adobe·illustrator
红尘散仙1 小时前
从 dsh 的插件系统出发:为什么我要探索 WIT 与 Wasm Component Model
rust·typescript·webassembly
红尘散仙1 小时前
从 WIT 到 Wasmtime:构建 Rust Component 工程
rust·typescript·webassembly
记忆张量MemTensor4 小时前
产品更新|MemOS 现已支持 DeepSeek Harness 长期记忆接入
人工智能·typescript·开源·agent
半个落月6 小时前
从 "use client" 到 Route Handler:用 Todos 理解 Next.js 水合与全栈请求
前端·react.js·next.js
记忆张量MemTensor9 小时前
MemOS Skill 上线|一句话即可接入 MemOS Cloud
大数据·数据库·人工智能·typescript·开源
xy34539 小时前
Axure 9.0 条形图绘制超详细教程:静态展示
ui·产品经理·axure·条形图
ITmaster073110 小时前
Vibe Coding 时代:Vue 消失了还是 React 太强?
前端·vue.js·react.js