Search
 
SCRIPT & CODE EXAMPLE
 

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') );
Comment

PREVIOUS NEXT
Code Example
Javascript :: removing the first match in array 
Javascript :: giftedchat anpm 
Javascript :: js change img ssrc 
Javascript :: Class Has a Constructor Function 
Javascript :: React Native Component with Random Hexa 
Javascript :: [jQuery] Moving elements in dom 
Javascript :: i18next plural not working 
Javascript :: s3 getobject not getting large json object 
Javascript :: Backbone Models In Collection Is Added Here 
Javascript :: Error: Minified React error #321 
Javascript :: JavaScript substring when we choose negative and zero number 
Javascript :: bun javascript runtime 
Javascript :: angularjs $q all hash 
Javascript :: knex js how to group by many items 
Javascript :: javascript online string concatenation 
Javascript :: hide Card Number Format 
Javascript :: Minimum Path Sum for loop 
Javascript :: javascript class is not defined 
Javascript :: Change slick slider slides from another component 
Javascript :: jquery code convert into javascript online 
Javascript :: añadir input file a formdata javascript 
Javascript :: decode jwt token online 
Javascript :: Ajax in wordpredss 
Javascript :: $( ) jquery 
Javascript :: how to create a new window with a specifc link jquery 
Javascript :: how to add another model into type of model in mongodb schema 
Javascript :: image gallery functions 
Javascript :: javascript Scroll into a div that is hidden initially in react 
Javascript :: angularjs Uncaught ReferenceError: myFunction is not defined at HTMLInputElement.onkeyup 
Javascript :: object Promise showing instead of data pulled from API call 
ADD CONTENT
Topic
Content
Source link
Name
2+5 =