Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

react button on child Content Data initialize

class App extends React.Component {
  constructor(props) {
    super(props);
    
    this.state = {
      data: 'Initial data...'
    }
    this.updateState = this.updateState.bind(this);
    
  };
  updateState() {
    this.setState({data: 'Data upDate from child component...'})
  }
  render() {
    return (
    <>
        <Content myDataProp = {this.state.data} updateStateProp = {this.updateState}></Content>
        </>
    );
  }
}
  class Content extends React.Component {
  render() {
    return (
    <>
        <button onClick = {this.props.updateStateProp}>Click</button>
        <h4>{this.props.myDataProp}</h4>
        </>
             );
  }
}

        ReactDOM.render(
        <App />, document.getElementById('mountNode') );
Source by jscomplete.com #
 
PREVIOUS NEXT
Tagged: #react #button #child #Content #Data #initialize
ADD COMMENT
Topic
Name
8+9 =