Skip to content

Instantly share code, notes, and snippets.

@kdabir
Last active August 4, 2016 03:44
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 kdabir/2c60202a7b3c9b3a007c624ef616808b to your computer and use it in GitHub Desktop.
Save kdabir/2c60202a7b3c9b3a007c624ef616808b to your computer and use it in GitHub Desktop.
Creating React Components. Three flavours. Stateless component with only one expression, with multiline expression and with complete class
import React from 'react';
export default class ClassBasedComponent extends React.Component {
constructor(props) {
super(props);
// do something useful
}
componentWillMount() {
// do something useful
}
componentDidMount() {
// do something useful
}
render() {
return (
<div>Hello</div>
);
}
componentWillUnmount() {
// do something useful
}
}
import React from 'react';
export default MultilineStatelessComponent = ({children, otherProp}) => {
const myId = otherProp + "id" || "defaultId";
return (
<div id={myId}>
{children}
</div>
);
}
import React from 'react';
export default SingleExpressionStatelessComponent = ({children, otherProp}) =>
<div id={otherProp}>
{children}
</div>
;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment