From 7b8b65d63e4014857484152fece0a77af42ba8db Mon Sep 17 00:00:00 2001 From: Cheton Wu Date: Fri, 10 Aug 2018 17:58:27 +0800 Subject: [PATCH] Address an issue where checking element type for imported components is not possible with projects using react-hot-loader --- src/CheckboxGroup.jsx | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/CheckboxGroup.jsx b/src/CheckboxGroup.jsx index a660756..c8e0347 100644 --- a/src/CheckboxGroup.jsx +++ b/src/CheckboxGroup.jsx @@ -4,6 +4,8 @@ import PropTypes from 'prop-types'; import React, { cloneElement, PureComponent } from 'react'; import Checkbox from './Checkbox'; +const getComponentType = (Component) => (Component ? ().type : undefined); + class CheckboxGroup extends PureComponent { static propTypes = { disabled: PropTypes.bool, @@ -58,12 +60,12 @@ class CheckboxGroup extends PureComponent { return child; } - if (child.type === CheckboxGroup) { + if (child.type === getComponentType(CheckboxGroup)) { // No nested checkbox groups return child; } - if (child.type === Checkbox) { + if (child.type === getComponentType(Checkbox)) { return cloneElement(child, { checked: this.state.value.indexOf(child.props.value) >= 0, disabled: this.props.disabled || child.props.disabled,