-
Notifications
You must be signed in to change notification settings - Fork 7.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Document React.pure #1266
Document React.pure #1266
Conversation
Deploy preview for reactjs ready! Built with commit 6bb9e96 |
const MyComponent = React.pure(render, equals); | ||
``` | ||
|
||
This method only exists as a **[performance optimization](/docs/optimizing-performance.html).** Do not rely on it to "prevent" a rendering, as this can lead to bugs. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This method only exists as a **[performance optimization](/docs/optimizing-performance.html).** Do not rely on it to "prevent" a rendering, as this can lead to bugs. | |
This method only exists as a **[performance optimization](/docs/optimizing-performance.html).** Do not rely on it to "prevent" a render, as this can lead to bugs. |
@@ -26,6 +26,10 @@ React components let you split the UI into independent, reusable pieces, and thi | |||
|
|||
If you don't use ES6 classes, you may use the `create-react-class` module instead. See [Using React without ES6](/docs/react-without-es6.html) for more information. | |||
|
|||
React components can also be defined as functions which can be wrapped by further functionality. | |||
|
|||
- [`React.pure`](#reactpure) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- [`React.pure`](#reactpure) | |
- [`React.memo`](#reactmemo) |
### `React.pure` | ||
|
||
```javascript | ||
const MyComponent = React.pure(function(props) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const MyComponent = React.pure(function(props) { | |
const MyComponent = React.memo(function(props) { |
}); | ||
``` | ||
|
||
`React.pure` is a [higher order component](/docs/higher-order-components.html). It's similar to [`React.PureComponent`](#reactpurecomponent) but for function components instead of classes. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
`React.pure` is a [higher order component](/docs/higher-order-components.html). It's similar to [`React.PureComponent`](#reactpurecomponent) but for function components instead of classes. | |
`React.memo` is a [higher order component](/docs/higher-order-components.html). It's similar to [`React.PureComponent`](#reactpurecomponent) but for function components instead of classes. |
|
||
`React.pure` is a [higher order component](/docs/higher-order-components.html). It's similar to [`React.PureComponent`](#reactpurecomponent) but for function components instead of classes. | ||
|
||
If your function component renders the same result given the same props, you can wrap it in a call to `React.pure` for a performance boost in some cases by memoizing the result. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If your function component renders the same result given the same props, you can wrap it in a call to `React.pure` for a performance boost in some cases by memoizing the result. | |
If your function component renders the same result given the same props, you can wrap it in a call to `React.memo` for a performance boost in some cases by memoizing the result. |
otherwise return false | ||
*/ | ||
} | ||
const MyComponent = React.pure(render, equals); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const MyComponent = React.pure(render, equals); | |
const MyComponent = React.memo(render, equals); |
@@ -88,6 +92,42 @@ If your React component's `render()` function renders the same result given the | |||
|
|||
* * * | |||
|
|||
### `React.pure` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
### `React.pure` | |
### `React.memo` |
facebook/react#13748
Pretty straight forward.
Still undecided whether we should support forwardRef by default or not. facebook/react#13822