Skip to content

Commit 2e5cb11

Browse files
committed
Fix circular reference error when passing component as left/right selectors.
1 parent 62b5952 commit 2e5cb11

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-native-calendar-strip",
3-
"version": "1.2.1",
3+
"version": "1.2.2",
44
"description": "Easy to use and visually stunning calendar component for React Native",
55
"main": "index.js",
66
"directories": {

src/WeekSelector.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,15 @@ class WeekSelector extends Component {
3030
};
3131

3232
shouldComponentUpdate(nextProps) {
33-
return JSON.stringify(this.props) !== JSON.stringify(nextProps);
33+
// Extract iconComponent since JSON.stringify fails on React component circular refs
34+
let _nextProps = Object.assign({}, nextProps);
35+
let _props = Object.assign({}, this.props);
36+
37+
delete _nextProps.iconComponent;
38+
delete _props.iconComponent;
39+
40+
return JSON.stringify(_props) !== JSON.stringify(_nextProps) &&
41+
this.props.iconComponent !== nextProps.iconComponent;
3442
}
3543

3644
isEnabled(controlDate, weekStartDate, weekEndDate) {
@@ -63,7 +71,7 @@ class WeekSelector extends Component {
6371
const opacity = { opacity: enabled ? 1 : 0 };
6472

6573
let component;
66-
if (React.Component.isPrototypeOf(iconComponent)) {
74+
if (React.isValidElement(iconComponent)) {
6775
component = React.cloneElement(iconComponent, {
6876
style: [iconComponent.props.style, { opacity: opacity.opacity }]
6977
});

0 commit comments

Comments
 (0)