【发布时间】:2019-07-25 13:15:32
【问题描述】:
你好,我是 React Native 中的新手,使用 typescript,在这个示例代码中,我想从父类的 parentCall 函数中的子组件调用 testChild 函数,但我不知道如何保留每个子组件的引用 我无法更改子组件代码 如何为每个子组件调用 testChild?
class parent extends React.Component {
public render(): JSX.Element {
return (
<child/>
<child/>
)
public parentCall(): void{
//call testChild for each Child component ??
}
}
class child extends React.Component {
public render(): JSX.Element {
return (
<Text>Text</Text>
)
public testChild (): string{
return Data ;
}
【问题讨论】: