Skip to content

Instantly share code, notes, and snippets.

@dvtng
Last active April 23, 2021 17:49
Show Gist options
  • Save dvtng/652b518a3fb8536329620e0b1998dbb7 to your computer and use it in GitHub Desktop.
Save dvtng/652b518a3fb8536329620e0b1998dbb7 to your computer and use it in GitHub Desktop.
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>
);
}
}
@hh-lohmann
Copy link

@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