How does a child component pass a value to a parent component, reactjs?

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;
Mar.31,2021

returns the callback function.
write a function change () {}
in the parent component, then pass it to the child component through props, and then call this.props.change ()
in the child component's click function. It's all in the official documentation of react.


A parent-child component passes a value, props

1. Parent component
onChange (used to receive values passed by child components) {

}

< Child_1 name= "Zhang San" age= "25" onChange= {this.onChange.bind (this)} / >

2. Subcomponent

this.props.onChange (passed value)

two redux

about the use of redux, please see my personal blog http://www.liuweibo.cn/blog

.
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1eacf76-211e.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1eacf76-211e.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?