REACT Secondary Components and subcomponents binding problems

In the project, we may encounter such a scene, which is the two-way data binding of the parent sub-component

react 中父组件与子组件双向绑定问题

First, introduce the React in the head in the head. JS, React-Dom.js and Optional Babel.js (here you need to pay attention to the order of reference, React.js must be before react-dom.js)

           Newly built a new hanging in Body 

   can then start writing JSX Note that the Script tag needs to indicate the type type "text / Babel" or "text / jsx" 

// parent component Class Father Extends React.comPonent {Constructor (Props) {Super (Props) this.State = {FNAME: ‘Parent Components’, Fage: 18, Key: ”};} setfname (Event) {this.setState ({FNAME :, key:}; // Set the value value of the fname value INPUT; Key is used to monitor the value change} setfage (EVENT) {this.SetState ({Fage:, Key:})}}}} {this.setState ({FNAME: DATA.NAME}); this.setState ({FAGE : DATA.AGE});} render () {RETURN (

Parent component data

 Name   {this.State.namefValue} 
// Controlled Components When the INPUT value changes, the method setFName AGE { // sub-assembly Class Son Extends {super (props) this.State = {svname: this.props.fname, // Parent-passed the value of the parent component to svname svage:}} svname (EV ) {ConSole.Log ({svname:})}} {this:}}}}}}}}}}}}}} {// Console.log (svname) this.props.todata (data)} render () {RETURN ( Point IPA value Subface data
// The data of the parent component is passed to the sub-assembly in the sub-assembly tag. The sub-assembly is received by PROPS; when the key value changes, sub-component data update )}}



)}} The above is a two-way binding problem of the React Mid -fect component and sub-component introduced to you, I hope to have some peopleHelp, if you have any questions, please leave a message, the small package will reply to everyone in time!
© Copyright Notice
Just support it if you like
comment Grab the couch

Please log in to comment