Last active
August 4, 2016 03:44
-
-
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
This file contains hidden or 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
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 | |
} | |
} |
This file contains hidden or 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
import React from 'react'; | |
export default MultilineStatelessComponent = ({children, otherProp}) => { | |
const myId = otherProp + "id" || "defaultId"; | |
return ( | |
<div id={myId}> | |
{children} | |
</div> | |
); | |
} |
This file contains hidden or 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
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