Skip to content

Commit 791c00d

Browse files
committed
Ensure event listeners are removed when no longer necessary
# I think this is the React-correct way of doing things.
1 parent 7323b76 commit 791c00d

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

src/app/components/content/IsaacParsonsQuestion.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,12 @@ class IsaacParsonsQuestionComponent extends React.Component<IsaacParsonsQuestion
4444
window.addEventListener('keyup', this.onKeyUp);
4545
}
4646

47+
componentWillUnmount() {
48+
window.removeEventListener('mousemove', this.onMouseMove);
49+
window.removeEventListener('touchmove', this.onMouseMove);
50+
window.removeEventListener('keyup', this.onKeyUp);
51+
}
52+
4753
componentDidUpdate = (prevProps: IsaacParsonsQuestionProps, prevState: IsaacParsonsQuestionState) => {
4854
if (!prevProps.currentAttempt && !this.props.currentAttempt) {
4955
const defaultAttempt: ParsonsChoiceDTO = {

0 commit comments

Comments
 (0)