diff --git a/src/ReactCursorPosition.js b/src/ReactCursorPosition.js index 24e3fed8..91fdc136 100644 --- a/src/ReactCursorPosition.js +++ b/src/ReactCursorPosition.js @@ -221,19 +221,17 @@ export default class extends React.Component { } } - componentWillReceiveProps({ isEnabled: willBeEnabled }) { - const { isEnabled } = this.props; - const isEnabledWillChange = isEnabled !== willBeEnabled; - - if (!isEnabledWillChange) { + componentDidUpdate(prevProps) { + if (this.props.isEnabled === prevProps.isEnabled) { return; } - - if (willBeEnabled) { + + if (this.props.isEnabled) { this.enable(); } else { this.disable(); } + } componentWillUnmount() { diff --git a/test/ReactCursorPosition.spec.js b/test/ReactCursorPosition.spec.js index 4fed2f4e..305a73ff 100644 --- a/test/ReactCursorPosition.spec.js +++ b/test/ReactCursorPosition.spec.js @@ -1110,6 +1110,7 @@ describe('ReactCursorPosition', () => { }); it('can be disabled without remounting', () => { + const positionObserver = getMountedComponentTree({ isEnabled: true }); const instance = positionObserver.instance(); const spy = jest.spyOn(instance, 'disable');