Child.js:export default class Child extends Component { testFunc = () => { console.log("test") } componentDidMount() { this.props.onRef(this) }父.js:export default class Parent extends Component { render() { return ( <> <Child onRef = {ref => (this.child=ref)}> </Child> <Button onPress={this.child.testFunc()}></Button> </> ) }}我想知道如何從 React Native 的父組件調用子組件中的函數?我嘗試了上面的代碼,我收到錯誤“TypeError undefined is not an object (evaluate '_this.child.testFunc')。當我在這里嘗試建議的解決方案時遇到同樣的錯誤:Call child function from parent component in React Native。有人可以幫我嗎?
React-Native:從父組件調用組件內的函數
紅顏莎娜
2022-11-11 16:19:33