У меня есть 2 компонента родительский (LoginScreen) и дочерний (RegistrationSection).Дочерний компонент имеет кнопку onClick.Когда пользователь нажимает кнопку, мне нужно запустить функцию childcall () из родительского компонента, и это не работает для меня.Я получаю эту ошибку
_this.props.childcall is not a function.
(In '_this2.props.childcall()' is undefined)
У меня есть следующий код:
Parent
import React, {Component} from 'react';
import Wallpaper from './Wallpaper';
import SignupSection from './SignupSection';
export default class LoginScreen extends Component {
constructor(props) {
super(props)
}
childcall()
{
alert("hello , this call from child component");
}
render() {
return (
<Wallpaper>
<SignupSection
childcall ={this.childcall.bind(this)}
/>
</Wallpaper>
);
}
}
Ребенок
import React, {Component} from 'react';
import PropTypes from 'prop-types';
import {StyleSheet, View, Text} from 'react-native';
export default class SignupSection extends Component {
constructor(props) {
super(props)
}
componentWillMount()
{
}
render() {
return (
<View style={styles.container}>
<Text style={styles.text} onPress={()=>this.props.childcall()}>Create Account</Text>
<Text style={styles.text}>Forgot Password?</Text>
</View>
);
}
}