The parent component of the relevant code:
React Import, {from} the Component 'REACT'; // introduced correlation module Import from Child '@ / Child' ; export default class extends Component { constructor (props) { super(props); this.state = { } } getData (str) { console.log(str) } // receiving subassembly data transmission over the render () { return ( <div> { / * where the parent component invokes subassembly similar to the subassembly function adds a property, must pay attention to this point the problem * / } <= {Fn Child the this .getData.bind ( the this )} /> </div> ) } }
Subcomponents relevant code:
import React, { Component } from 'react' class Com extends Component { render () // return ( // <Button this.sendData.bind the onClick = {(the this)}> to a parent element by value </ Button> // ) { return ( // the console.log (this.props) Fn // sub performed by components may be passed over the parent component functions Fn () to pass parameters <Button the onClick = {() => the this .props.fn ( '11111')}> </ Button> ) } } export default Com;
Our family react more complete sub-assemblies pass values to the parent component