Skip to content

Instantly share code, notes, and snippets.

@agl0809
Last active October 10, 2018 09:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save agl0809/c1988560aa11787ad310c3eb45e460f5 to your computer and use it in GitHub Desktop.
Save agl0809/c1988560aa11787ad310c3eb45e460f5 to your computer and use it in GitHub Desktop.
React component using class
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