Horje
reactjs lifecycle class components Code Example
reactjs lifecycle class components
import React from 'react';
import ReactDOM from 'react-dom';
 
class Test extends React.Component {
    constructor(props)
    {
        super(props);
        this.state = { hello : "World!" };
    }
 
    componentWillMount()
    {
        console.log("componentWillMount()");
    }
 
    componentDidMount()
    {
        console.log("componentDidMount()");
    }
 
    changeState()
    {
        this.setState({ hello : "Geek!" });
    }
 
    render()
    {
        return (
            <div>
            <h1>GeeksForGeeks.org, Hello{ this.state.hello }</h1>
            <h2>
            <a rel="nofollow" onClick={this.changeState.bind(this)}>Press Here!</a>
            </h2>
            </div>);
    }
 
    shouldComponentUpdate(nextProps, nextState)
    {
        console.log("shouldComponentUpdate()");
        return true;
    }
 
    componentWillUpdate()
    {
        console.log("componentWillUpdate()");
    }
 
    componentDidUpdate()
    {
        console.log("componentDidUpdate()");
    }
}
 
ReactDOM.render(
    <Test />,
    document.getElementById('root'));




Javascript

Related
javascript apply Code Example javascript apply Code Example
How does logical operators or || works in javascript? Code Example How does logical operators or || works in javascript? Code Example
fuzzy search javascript Code Example fuzzy search javascript Code Example
how to create an object in javascript Code Example how to create an object in javascript Code Example
javascript find the longest string in array Code Example javascript find the longest string in array Code Example

Type:
Code Example
Category:
Coding
Sub Category:
Code Example
Uploaded by:
Admin
Views:
8