Created
October 22, 2017 06:08
-
-
Save tkssharma/124e61f3e9732e0c11b6b2230b5a9d30 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
shouldComponentUpdate (nextProps) { | |
// have any of the items changed? | |
if(!isArrayEqual(this.props.items, nextProps.items)){ | |
return true; | |
} | |
// everything from here is horrible. | |
// if interaction has not changed at all then when can return false (yay!) | |
if(isObjectEqual(this.props.interaction, nextProps.interaction)){ | |
return false; | |
} | |
// at this point we know: | |
// 1. the items have not changed | |
// 2. the interaction has changed | |
// we need to find out if the interaction change was relevant for us | |
const wasItemSelected = this.props.items.any(item => { | |
return item.id === this.props.interaction.selectedId | |
}); | |
const isItemSelected = nextProps.items.any(item => { | |
return item.id === nextProps.interaction.selectedId | |
}); | |
// return true when something has changed | |
// return false when nothing has changed | |
return wasItemSelected !== isItemSelected; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment