Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

react extends component Increment data

class App extends React.Component {
  constructor(props) {
    super(props);
    
    this.state = {
      data : 0
    }
    this.setNewNumber = this.setNewNumber.bind(this)
  };
  setNewNumber() {
    this.setState({data : this.state.data+1})
  }
  render(){
    return (
    <>
        <button onClick = {this.setNewNumber}>Increment</button>
        <Content myNumber = {this.state.data}>0</Content>
          </>
  );
}
}

class Content extends React.Component {
  componentWillMount(){
    console.log('Component will MOUNT!')
  }
  componentDidMount(){
    console.log('Component DID MOUNT!')
  }
  componentWillReceiveProps(newProps){
    console.log('COmponent will RECEIVE PROPS')
  }
  shouldComponentUpdate(newProps, newState){
    return true;
  }
   componentWillUpdate(nextProps, nextState){
    console.log('COmponent Will Update!')
  }
   componentDidUpdate(prevProps, prevState){
    console.log('COmponent DID Update!')
  }
  componentWillUnmount() {
    console.log('COmponent Will Unmount!')
  }
  
  render() {
    return(
    <>
        <h3> {this.props.myNumber}</h3>
        </>
    );
  }
  
  }
ReactDOM.render(
<App /> , document.getElementById ('mountNode'));
Comment

PREVIOUS NEXT
Code Example
Javascript :: create relationship between schema in sanity 
Javascript :: document.getelementsbyclassname equivalent in jquery 
Javascript :: recaptcha v3 
Javascript :: switch variables javascript 
Javascript :: enzyme test method 
Javascript :: angular print html 
Javascript :: how to copy object in javascript 
Javascript :: get character length javascript 
Javascript :: notification like whatsapp in jquery 
Javascript :: django pointfield json example 
Javascript :: node load testing-check 
Javascript :: js min number in array 
Javascript :: react native floating action button 
Javascript :: attr jquery 
Javascript :: javascript desktop app 
Javascript :: javascript link to google maps route 
Javascript :: jest test thunk 
Javascript :: jquery generate post entire page 
Javascript :: javascript function to sleep 
Javascript :: get difference of minutes between two time based on am, pm 
Javascript :: jest simulate toggle switch rn 
Javascript :: Axios with React Hooks, “traditional” Promise syntax 
Javascript :: export socket io connection in react 
Javascript :: defaultdeep lodash 
Javascript :: array con doble javascript 
Javascript :: return array javascript 
Javascript :: e.target.id not working react js 
Javascript :: inertia-link vuetify 
Javascript :: sending api request in axios with files 
Javascript :: Jquery check if hover over child element 
ADD CONTENT
Topic
Content
Source link
Name
3+4 =