【发布时间】:2021-06-20 04:31:25
【问题描述】:
我想以这种方式在我的组件中声明类型,我已经看到使用类可以做到这一点,但是如何使用函数式组件来实现呢?无需导出界面?我已经研究了很多,但没有发现任何关于它的信息。
const Elem1 = forwardRef((props : any, ref : { open()? : void }) => {
useImperativeHandle(ref, () => ({
open: () => console.log('opened')
}))
....
})
const Elem2 = () => {
const elem1Ref = useRef<Elem1>()
elem1Ref?.current?.open()
....
}
【问题讨论】:
标签: javascript typescript react-native ecmascript-6