-
-
Save imdongchen/2bfecea42c2649b4eeea4658d1d2ec68 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
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