The "React" sub-component passes the value to the parent component

Source: Internet
Author: User

The black box is the parent, the green Box is a child, and the red box is grandson. The parent passes the value to the descendants of the props; the descendants pass the value to the parent, to set the receive function and state in the parent, and to pass the function name to the descendants with props. I do not want to pass the value directly to the superior, want to add "@china" after the name, gender and "people". Take a look at the next article

vargrandson =React.createclass ({render:function () {return (            <div Style={{border:"1px solid Red", margin:"10px"}}>{ This.}:<Selectonchange={ This.props.handleselect}> <option value="male"> Men </option> <option value="female"> Women </option> </Select> </div>        )    }});varChild =React.createclass ({render:function () {return (            <div Style={{border:"1px solid Green", margin:"10px"}}>                { This.}:<input onchange={ This.props.handleval}/> <grandson name="Sex"handleselect={ This.props.handleselect}/> </div>        )    }});varParent =React.createclass ({getinitialstate:function () {return{username:"', Sex:"'}}, Handleval:function (Event){         This. SetState ({username:Event. Target.value}); }, Handleselect:function (Event) {         This. setState ({sex:Event. Target.value}); }, Render:function () {return (            <div Style={{border:"1px solid #000", padding:"10px"}}> <div> User name: { This.state.username}</div> <div> User gender: {}</div> <child name="name"handleval={ This. Handleval} handleselect={ This.handleselect}/> </div>        )    }}); React.render (<parent/>, document.getElementById ('Test'));

The "React" sub-component passes the value to the parent component

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.