function in class component code example

Example 1: class component params in react

<input 
		type= "text"
     	value={ this.state.value || "" }
     	placeholder="Enter Name"
/>

Example 2: function inside a class component react

export default class Archive extends React.Component { 

    saySomething(something) {
        console.log(something);
    }

    handleClick(e) {
        this.saySomething("element clicked");
    }

    componentDidMount() {
        this.saySomething("component did mount");
    }

    render() {
        return <button onClick={this.handleClick.bind(this)} value="Click me" />;
    }
}

Tags:

C Example