Here's an example from a Modal component I wrote last week. It has a prop called "dismissOnEsc" which allows the consumer to decide if hitting the ESC key will dismiss the Modal. If (for whatever dumb reason) the consumer didn't want ESC to dismiss the Modal, but later on in the components life cycle decided that it should, well then nothing would happen because the event listener is registered in componentDidMount and the component wasn't remounted, it's props just changed.
Here's the relevant snippet of code:
componentWillReceiveProps(nextProps) {
if (canUseDOM) {
if (nextProps.dismissOnEsc && !this.props.dismissOnEsc) {
this.registerEscListener();
} else if (!nextProps.dismissOnEsc && this.props.dismissOnEsc) {
this.unregisterEscListener();
}
}
}
If you need me to explain further / show you the full code, just ask, I don't mind.