Last active
October 10, 2018 09:28
-
-
Save agl0809/c1988560aa11787ad310c3eb45e460f5 to your computer and use it in GitHub Desktop.
React component using class
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MyComponent extends React.Component { | |
constructor(props) { | |
super(props); | |
this.state = { | |
title: "Hello React !!!", | |
} | |
} | |
render() { | |
return ( | |
<div> | |
<h2> | |
{this.state.title} | |
</h2> | |
<p>User Name: {this.props.name}</p> | |
<p>User Age: {this.props.age}</p> | |
</div> | |
); | |
} | |
} | |
MyComponent.propTypes ={ | |
name:PropTypes.string.isRequired, | |
age:PropTypes.number.isRequired | |
} | |
MyComponent.defaultProps = { | |
name: 'Pankaj Kumar Choudhary', | |
age: 24 | |
}; | |
export default MyComponent; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment