Skip to content
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

Improve readability of isValidElementType #19251

Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
replace condition by switch/case
  • Loading branch information
behnammodi committed Jul 4, 2020
commit ed83ee159e781d9f6cc7006d97afbb2b54c9f85d
23 changes: 11 additions & 12 deletions packages/shared/isValidElementType.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,17 @@ import {
export default function isValidElementType(type: mixed) {
if (typeof type === 'string' || typeof type === 'function') return true;
behnammodi marked this conversation as resolved.
Show resolved Hide resolved

if (
[
REACT_FRAGMENT_TYPE,
REACT_PROFILER_TYPE,
REACT_DEBUG_TRACING_MODE_TYPE,
REACT_STRICT_MODE_TYPE,
REACT_SUSPENSE_TYPE,
REACT_SUSPENSE_LIST_TYPE,
REACT_LEGACY_HIDDEN_TYPE,
].indexOf(type) !== -1
)
return true;
switch (type) {
case REACT_FRAGMENT_TYPE:
case REACT_PROFILER_TYPE:
case REACT_DEBUG_TRACING_MODE_TYPE:
case REACT_STRICT_MODE_TYPE:
case REACT_SUSPENSE_TYPE:
case REACT_SUSPENSE_LIST_TYPE:
case REACT_LEGACY_HIDDEN_TYPE: {
return true;
}
}

if (typeof type === 'object' && type !== null) {
if (
Expand Down