react-native 父函数组件调用类子组件的方法
作者:互联网
import React, {Component} from 'react'; import {Text, View, TouchableOpacity} from 'react-native'; // 父 let child onRefbbb = (ref) => { child = ref } clickccc = () => { child.myName() } const Parent =()=> { return( <View> <Child onRefaaa={onRefbbb} /> <TouchableOpacity onPress={()=>clickccc()}> <Text>onClick</Text> </TouchableOpacity> </View> ) } export default Parent // 子 class Child extends Component { componentDidMount(){ this.props.onRefaaa(this) } myName = () =>{ alert(11111111111111) } render() { return (<View></View>) } }
标签:类子,Parent,Component,clickccc,react,child,组件,native 来源: https://www.cnblogs.com/tlfe/p/16671868.html