mirror of
https://github.com/zebrajr/react.git
synced 2026-01-15 12:15:22 +00:00
Improve readability of isValidElementType (#19251)
* improve readability * replace condition by switch/case * replace condition by switch/case * remove unnecessary braces * replace switch/case to ifs * replace switch/case to ifs * fix by multiline if statements * fix multiple if statements
This commit is contained in:
@@ -28,28 +28,39 @@ import {
|
||||
} 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.
|
||||
if (typeof type === 'string' || typeof type === 'function') {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Note: typeof might be other than 'symbol' or 'number' (e.g. if it's a polyfill).
|
||||
if (
|
||||
type === REACT_FRAGMENT_TYPE ||
|
||||
type === REACT_PROFILER_TYPE ||
|
||||
type === REACT_DEBUG_TRACING_MODE_TYPE ||
|
||||
type === REACT_STRICT_MODE_TYPE ||
|
||||
type === REACT_SUSPENSE_TYPE ||
|
||||
type === REACT_SUSPENSE_LIST_TYPE ||
|
||||
type === REACT_LEGACY_HIDDEN_TYPE ||
|
||||
(typeof type === 'object' &&
|
||||
type !== null &&
|
||||
(type.$$typeof === REACT_LAZY_TYPE ||
|
||||
type.$$typeof === REACT_MEMO_TYPE ||
|
||||
type.$$typeof === REACT_PROVIDER_TYPE ||
|
||||
type.$$typeof === REACT_CONTEXT_TYPE ||
|
||||
type.$$typeof === REACT_FORWARD_REF_TYPE ||
|
||||
type.$$typeof === REACT_FUNDAMENTAL_TYPE ||
|
||||
type.$$typeof === REACT_RESPONDER_TYPE ||
|
||||
type.$$typeof === REACT_SCOPE_TYPE ||
|
||||
type.$$typeof === REACT_BLOCK_TYPE ||
|
||||
type[(0: any)] === REACT_SERVER_BLOCK_TYPE))
|
||||
);
|
||||
type === REACT_LEGACY_HIDDEN_TYPE
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (typeof type === 'object' && type !== null) {
|
||||
if (
|
||||
type.$$typeof === REACT_LAZY_TYPE ||
|
||||
type.$$typeof === REACT_MEMO_TYPE ||
|
||||
type.$$typeof === REACT_PROVIDER_TYPE ||
|
||||
type.$$typeof === REACT_CONTEXT_TYPE ||
|
||||
type.$$typeof === REACT_FORWARD_REF_TYPE ||
|
||||
type.$$typeof === REACT_FUNDAMENTAL_TYPE ||
|
||||
type.$$typeof === REACT_RESPONDER_TYPE ||
|
||||
type.$$typeof === REACT_SCOPE_TYPE ||
|
||||
type.$$typeof === REACT_BLOCK_TYPE ||
|
||||
type[(0: any)] === REACT_SERVER_BLOCK_TYPE
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user