Last active
April 23, 2021 17:49
-
-
Save dvtng/652b518a3fb8536329620e0b1998dbb7 to your computer and use it in GitHub Desktop.
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
const PanelHeader = (props) => ( | |
// ... | |
); | |
const PanelBody = (props) => ( | |
// ... | |
); | |
class Panel extends React.Component { | |
render() { | |
return ( | |
<div> | |
// Nice and explicit about which props are used | |
<PanelHeader title={this.props.title}/> | |
<PanelBody content={this.props.content}/> | |
</div> | |
); | |
} | |
} |
@aamaclaren & future readers: Omitting curlies on arrow functions implies "return", i.e. with curlies you would need also an explicit "return" statement. Parentheses allow "line breaks" for human readers, while keeping it as one line = one statement for JS, and with only one statement you don't need curlies. Often used for code golfing, with React it supports the declarative view on components as soon as you are used to it or if you got onboarded without any JS knowledge at all.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Should the PanelHeader and PanelBody arrow functions use curly braces for the function body? Looks like using parentheses causes an error.