Skip to content

Instantly share code, notes, and snippets.

@imdongchen
Created October 2, 2018 14:53
Show Gist options
  • Save imdongchen/2bfecea42c2649b4eeea4658d1d2ec68 to your computer and use it in GitHub Desktop.
Save imdongchen/2bfecea42c2649b4eeea4658d1d2ec68 to your computer and use it in GitHub Desktop.
MyComponent extends React.Component {
render() {
return (
<div>
{this.renderItemA()}
{this.renderItemB()}
{this.renderItemC()}
{this.renderItemD()}
</div>
)
}
}
```
The `render()` method in a component includes several “sub render“ method. In such a situation, it’s highly likely you can extract each sub render method into a separate component. It makes the parent component look cleaner, smaller, easier to read and test.
## Tip Four: Don’t pre-optimize component performance
I often see advice against inline function because it will hit performance:
```js
function MyComponent() {
return (
<InnerComponent title={title} onClick={() => { /* do something */ }} /> // the inline function will always cause re-render
)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment