[react 3种方法] 获取ant组件ref用ts如何定义?

获取ant的轮播图组件, 我用ts如何定义?

Strongly Type useRef with ElementRef | Total TypeScript

javascript 复制代码
import React, {  ElementRef } from 'react';
javascript 复制代码
 const lunboRef = useRef<ElementRef<typeof Carousel>>(null);
javascript 复制代码
    <Carousel autoplay ref={lunboRef}>

这样就行了! ,然后点一下看看.弹出提示了

当然你还可以用ant内置的GetRef

Type Util - Ant Design

这个2个一样

javascript 复制代码
    const lunboRef = useRef<GetRef<typeof Carousel>>(null);
    // const lunboRef = useRef<ElementRef<typeof Carousel>>(null);

最后一种

ComponentRef

javascript 复制代码
import React, { useRef, ComponentRef } from 'react';
useRef<ComponentRef<typeof Carousel>>(null);
相关推荐
Dragon Wu9 分钟前
Electron Forge集成React Typescript完整步骤
前端·javascript·react.js·typescript·electron·reactjs
We་ct15 小时前
LeetCode 56. 合并区间:区间重叠问题的核心解法与代码解析
前端·算法·leetcode·typescript
程序猿阿伟1 天前
《TypeScript中Protobuf到运行时类型安全的转换指南》
javascript·安全·typescript
We་ct1 天前
LeetCode 228. 汇总区间:解题思路+代码详解
前端·算法·leetcode·typescript
阿蒙Amon1 天前
TypeScript学习-第10章:模块与命名空间
学习·ubuntu·typescript
VT.馒头2 天前
【力扣】2695. 包装数组
前端·javascript·算法·leetcode·职场和发展·typescript
AAA阿giao2 天前
从零拆解一个 React + TypeScript 的 TodoList:模块化、数据流与工程实践
前端·react.js·ui·typescript·前端框架
hedley(●'◡'●)2 天前
基于cesium和vue的大疆司空模仿程序
前端·javascript·vue.js·python·typescript·无人机
百锦再2 天前
Vue高阶知识:利用 defineModel 特性开发搜索组件组合
前端·vue.js·学习·flutter·typescript·前端框架
全栈探索者2 天前
@Component + struct = 你的新函数组件——React 开发者的鸿蒙入门指南(第 2 期)
react·harmonyos·arkts·前端开发·deveco studio·鸿蒙next·函数组件