Skip to content

Commit

Permalink
Fix circular reference error when passing component as left/right sel…
Browse files Browse the repository at this point in the history
…ectors.
  • Loading branch information
peacechen committed Aug 10, 2017
1 parent 62b5952 commit 2e5cb11
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-native-calendar-strip",
"version": "1.2.1",
"version": "1.2.2",
"description": "Easy to use and visually stunning calendar component for React Native",
"main": "index.js",
"directories": {
Expand Down
12 changes: 10 additions & 2 deletions src/WeekSelector.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,15 @@ class WeekSelector extends Component {
};

shouldComponentUpdate(nextProps) {
return JSON.stringify(this.props) !== JSON.stringify(nextProps);
// Extract iconComponent since JSON.stringify fails on React component circular refs
let _nextProps = Object.assign({}, nextProps);
let _props = Object.assign({}, this.props);

delete _nextProps.iconComponent;
delete _props.iconComponent;

return JSON.stringify(_props) !== JSON.stringify(_nextProps) &&
this.props.iconComponent !== nextProps.iconComponent;
}

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

let component;
if (React.Component.isPrototypeOf(iconComponent)) {
if (React.isValidElement(iconComponent)) {
component = React.cloneElement(iconComponent, {
style: [iconComponent.props.style, { opacity: opacity.opacity }]
});
Expand Down

0 comments on commit 2e5cb11

Please sign in to comment.