【发布时间】:2020-08-10 22:47:01
【问题描述】:
我正在使用 Hooks 开发一个 React Native 应用程序。 (无课程)。当我们使用类时,我们可以像这样为子组件创建一个 ref。
<Child ref={component => this.childComponent = component} />
但是,当我们使用 Hooks 时该怎么做呢?
我想要这样的东西。
export default function Child() {
const foo = () => {
//do something
}
return(
//something
)
}
export default function Parent() {
const myFunc = () => {
ref.foo();
}
return(
<Child ref={.........} /> //This is what I want to know how to do?
)
}
我希望你明白我想说什么。
【问题讨论】:
标签: javascript react-native react-hooks ref