Skip to content
This repository was archived by the owner on Jun 2, 2024. It is now read-only.

Commit fc15e6a

Browse files
committed
fix: fix switch iselement error on webpack
Resolves (#62)
1 parent d974ed6 commit fc15e6a

File tree

4 files changed

+4
-15
lines changed

4 files changed

+4
-15
lines changed

src/components/Switch/Switch.tsx

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import * as PropTypes from 'prop-types';
22
import * as React from 'react';
33

44
import { TOutput } from '../../types';
5-
import { isElement } from '../../utils';
65
import SwitchCase from './SwitchCase';
76
import SwitchDefault from './SwitchDefault';
87

@@ -14,9 +13,7 @@ interface ISwitchProps {
1413
children: React.ReactNode;
1514
}
1615

17-
const isValidSwitchChild = (child: any) =>
18-
React.isValidElement(child) &&
19-
(isElement(child, SwitchCase) || isElement(child, SwitchDefault));
16+
const getSwitchCaseValue = (element: any) => element.props.value;
2017

2118
/**
2219
* Renders content from first `Switch.Case` that matches `value`, else `Switch.Default` if it exists.
@@ -28,15 +25,15 @@ const Switch = (props: ISwitchProps): TOutput => {
2825
let child: any;
2926

3027
React.Children.forEach(children, (element: any) => {
31-
if (match === false && isValidSwitchChild(element)) {
32-
const caseValue = element.props.value;
28+
if (match === false && React.isValidElement(element)) {
29+
const caseValue = getSwitchCaseValue(element);
3330
child = element;
3431
match = caseValue === switchValue;
3532
}
3633
});
3734

3835
// No match found, return default if it exists.
39-
if (!match && isElement(child, SwitchDefault)) {
36+
if (!match && getSwitchCaseValue(child) === undefined) {
4037
return React.cloneElement(child);
4138
}
4239

src/utils/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
export { default as getChildrenOrRender } from './getChildrenOrRender';
22
export { default as getRenderProp } from './getRenderProp';
3-
export { default as isElement } from './isElement';
43
export { default as isEmptyChildren } from './isEmptyChildren';
54
export { default as isFunction } from './isFunction';

src/utils/isElement/index.ts

Lines changed: 0 additions & 1 deletion
This file was deleted.

src/utils/isElement/isElement.ts

Lines changed: 0 additions & 6 deletions
This file was deleted.

0 commit comments

Comments
 (0)