Skip to content

Commit

Permalink
Rmv listener when unmount
Browse files Browse the repository at this point in the history
  • Loading branch information
nickolasbenakis authored and nickolasbenakis committed Dec 9, 2019
1 parent f8d95bf commit d1eb623
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/components/searchbar.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
/* eslint-disable jsx-a11y/label-has-associated-control */
/* eslint-disable jsx-a11y/label-has-for */
/* eslint-disable no-trailing-spaces */
/* eslint-disable jsx-a11y/no-autofocus */

import React from 'react';
import './searchbar.css';
import { connect } from 'react-redux';
Expand All @@ -13,6 +16,10 @@ class Searchbar extends React.Component {
document.addEventListener('keypress', this.handleFocus);
}

componentWillUnmount() {
document.removeEventListener('keypress', this.handleFocus);
}

handleFocus() {
this.searchBarRef.current.focus();
}
Expand All @@ -23,8 +30,6 @@ class Searchbar extends React.Component {
}

render() {
/* eslint-disable jsx-a11y/no-autofocus */
/* eslint-disable no-trailing-spaces */
const { search, searchbarFixed } = this.props;
return (
<div className={`search ${searchbarFixed ? 'search-fixed' : ''}`}>
Expand Down

0 comments on commit d1eb623

Please sign in to comment.