我就只想ts提示我暴露的getData 方法
import React, { Component, useRef } from 'react';
type childRef = {
getData: () => []
}
function Parent () {
const childref = useRef<childRef|null>(null)
// 这里这个ref标红
return <Child ref={childref}/>
}
type IChild = {
ref:childRef
}
class Child extends Component<IChild> {
getData = () => {
return []
}
render() {
return <div>Child</div>
}
}
好像没有写的那么复杂呀,。。我就这样就能识别getData了。。
补充根据题主需求更新的代码