获取ant的轮播图组件, 我用ts如何定义?
Strongly Type useRef with ElementRef | Total TypeScript
import React, { ElementRef } from 'react';
const lunboRef = useRef<ElementRef<typeof Carousel>>(null);
<Carousel autoplay ref={lunboRef}>
这样就行了! ,然后点一下看看.弹出提示了
当然你还可以用ant内置的GetRef
Type Util - Ant Design
这个2个一样
const lunboRef = useRef<GetRef<typeof Carousel>>(null);// const lunboRef = useRef<ElementRef<typeof Carousel>>(null);
最后一种
ComponentRef
import React, { useRef, ComponentRef } from 'react';
useRef<ComponentRef<typeof Carousel>>(null);