the parent component transmits the prop, to the child component.
how to transmit the value of the flag variable in the callback to the parent component through the click of the click event?
class Child_1 extends React.Component {//
constructor(props) {
super(props);
this.state = {
getName: this.props.name,
getAge: this.props.age,
}
}
click = () => {
let flag = "test";
}
render() {
const {getName, getAge} = this.state;
return (
<div>
{`:${getName}`}
{`:${getAge}`}
<div onClick={this.click}>click me</div>
</div>
)
}
}
export default Child_1;
import Child_1 from "./Child_1";
class Parent extends React.Component {//
constructor(props) {
super(props);
this.state = {}
}
componentDidMount() {
}
render() {
return (
<div>
<Child_1 name="" age="25"/>
</div>
)
}
}
export default Parent;