dillon1000/react

Commit

pure (#13748)

* 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 <[email protected]>
Co-authored-by: Sophie Alpert <[email protected]>

* Warn if first argument is not a functional component
Browse files
Changed paths10 files
First-parent comparison
M packages/react-reconciler/src/ReactFiber.js ModifiedM packages/react-reconciler/src/ReactFiberBeginWork.js ModifiedM packages/react-reconciler/src/ReactFiberCompleteWork.js ModifiedA packages/react-reconciler/src/__tests__/ReactPure-test.internal.js AddedM packages/react-test-renderer/src/ReactTestRenderer.js ModifiedM packages/react/src/React.js ModifiedA packages/react/src/pure.js AddedM packages/shared/ReactSymbols.js ModifiedM packages/shared/ReactWorkTags.js ModifiedM packages/shared/isValidElementType.js Modified
Patch

Files changed

Rendering syntax-highlighted changes…