获取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

这个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);