mirror of
https://github.com/facebook/react.git
synced 2026-02-26 18:58:05 +00:00
* 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
41 lines
1.1 KiB
JavaScript
41 lines
1.1 KiB
JavaScript
/**
|
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
*
|
|
* This source code is licensed under the MIT license found in the
|
|
* LICENSE file in the root directory of this source tree.
|
|
*
|
|
* @flow
|
|
*/
|
|
|
|
import {
|
|
REACT_CONCURRENT_MODE_TYPE,
|
|
REACT_CONTEXT_TYPE,
|
|
REACT_FORWARD_REF_TYPE,
|
|
REACT_FRAGMENT_TYPE,
|
|
REACT_PROFILER_TYPE,
|
|
REACT_PROVIDER_TYPE,
|
|
REACT_STRICT_MODE_TYPE,
|
|
REACT_PLACEHOLDER_TYPE,
|
|
REACT_PURE_TYPE,
|
|
} from 'shared/ReactSymbols';
|
|
|
|
export default function isValidElementType(type: mixed) {
|
|
return (
|
|
typeof type === 'string' ||
|
|
typeof type === 'function' ||
|
|
// Note: its typeof might be other than 'symbol' or 'number' if it's a polyfill.
|
|
type === REACT_FRAGMENT_TYPE ||
|
|
type === REACT_CONCURRENT_MODE_TYPE ||
|
|
type === REACT_PROFILER_TYPE ||
|
|
type === REACT_STRICT_MODE_TYPE ||
|
|
type === REACT_PLACEHOLDER_TYPE ||
|
|
(typeof type === 'object' &&
|
|
type !== null &&
|
|
(typeof type.then === 'function' ||
|
|
type.$$typeof === REACT_PURE_TYPE ||
|
|
type.$$typeof === REACT_PROVIDER_TYPE ||
|
|
type.$$typeof === REACT_CONTEXT_TYPE ||
|
|
type.$$typeof === REACT_FORWARD_REF_TYPE))
|
|
);
|
|
}
|