Skip to content

Commit

Permalink
pure (#13748)
Browse files Browse the repository at this point in the history
* pure

A higher-order component version of the `React.PureComponent` class.
During an update, the previous props are compared to the new props. If
they are the same, React will skip rendering the component and
its children.

Unlike userspace implementations, `pure` will not add an additional
fiber to the tree.

The first argument must be a functional component; it does not work
with classes.

`pure` uses shallow comparison by default, like `React.PureComponent`.
A custom comparison can be passed as the second argument.

Co-authored-by: Andrew Clark <acdlite@fb.com>
Co-authored-by: Sophie Alpert <sophiebits@fb.com>

* Warn if first argument is not a functional component
  • Loading branch information
acdlite committed Sep 27, 2018
1 parent 648bf73 commit ecd1dbb
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/ReactTestRenderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ import {
ForwardRef,
Profiler,
ForwardRefLazy,
PureComponent,
PureComponentLazy,
} from 'shared/ReactWorkTags';
import invariant from 'shared/invariant';
import ReactVersion from 'shared/ReactVersion';
Expand Down Expand Up @@ -199,6 +201,8 @@ function toTree(node: ?Fiber) {
case Profiler:
case ForwardRef:
case ForwardRefLazy:
case PureComponent:
case PureComponentLazy:
return childrenToTree(node.child);
default:
invariant(
Expand All @@ -217,6 +221,8 @@ const validWrapperTypes = new Set([
HostComponent,
ForwardRef,
ForwardRefLazy,
PureComponent,
PureComponentLazy,
// Normally skipped, but used when there's more than one root child.
HostRoot,
]);
Expand Down

0 comments on commit ecd1dbb

Please sign in to comment.