Merge pull request #615 from sachaaaaa/mainheader_stuff

mainheader: call setstate only when needed for clipboard
pull/617/head
sachaaaaa 6 years ago committed by GitHub
commit 4514c7b104
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -72,6 +72,7 @@ export class MainHeader extends React.Component<Props, any> {
private readonly setFocusBound: () => void; private readonly setFocusBound: () => void;
private readonly inputRef: React.RefObject<HTMLInputElement>; private readonly inputRef: React.RefObject<HTMLInputElement>;
private readonly debouncedSearch: (searchTerm: string) => void; private readonly debouncedSearch: (searchTerm: string) => void;
private readonly timerId: any;
constructor(props: Props) { constructor(props: Props) {
super(props); super(props);
@ -92,9 +93,11 @@ export class MainHeader extends React.Component<Props, any> {
this.debouncedSearch = debounce(this.search.bind(this), 20); this.debouncedSearch = debounce(this.search.bind(this), 20);
setInterval(() => { this.timerId = setInterval(() => {
const clipboardText = clipboard.readText(); const clipboardText = clipboard.readText();
this.setState({ clipboardText }); if (this.state.clipboardText !== clipboardText) {
this.setState({ clipboardText });
}
}, 100); }, 100);
} }
@ -103,6 +106,11 @@ export class MainHeader extends React.Component<Props, any> {
this.updateHasPass(); this.updateHasPass();
} }
public componentWillUnmount() {
// tslint:disable-next-line
clearInterval(this.timerId);
}
public componentDidUpdate(_prevProps: Props, prevState: any) { public componentDidUpdate(_prevProps: Props, prevState: any) {
if (prevState.hasPass !== this.state.hasPass) { if (prevState.hasPass !== this.state.hasPass) {
this.updateMenuItems(); this.updateMenuItems();

Loading…
Cancel
Save