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

运行结果如下

相关推荐
深兰科技9 小时前
走出进博展馆寻AI方案,巴西政商联合体参访深兰科技洽商中巴产业数字化合作
人工智能·typescript·深兰科技·中巴产业数字化·巴西政商联合体·ai方案·进博会
月夏13 小时前
我把全栈项目塞进已有 nginx 的服务器,卡我最久的是三个斜杠
nginx·react.js·docker
敲上瘾1 天前
Qt核心机制:信号与槽详解
开发语言·c++·qt·ui·qt6.3
FungLeo1 天前
成为全栈·Vue 管理后台篇·Biome、类型检查、构建和API 代理如何组成质量门禁
前端·javascript·vue.js·typescript·vite·前端工程化·biome
泯泷2 天前
改一个字,整段都红了?——中文内容差异对比的算法与协议设计
前端·javascript·typescript
4cos902 天前
pi学习笔记-AgentLoop
typescript
FRing032 天前
vue2干货总结10(json-server、vant-ui、postcss插件、axios二次封装、图形验证码、toast轻提示)
开发语言·前端·vue.js·ui·json·vue2·postcss
清晨Coding3 天前
为什么用 React Developer Tools 查看组件树这么乱?
前端·react.js
afumu3 天前
让本机 Agent 指挥浏览器里的多个网页 AI:一套 127.0.0.1 控制协议的设计取舍
chrome·typescript
xy34534 天前
Axure 9.0 垂直菜单介绍
ui·产品经理·axure·原型设计