Skip to content
This repository has been archived by the owner on Aug 18, 2023. It is now read-only.

Commit

Permalink
fix update when unmounted issue
Browse files Browse the repository at this point in the history
  • Loading branch information
eramdam committed Apr 10, 2021
1 parent 85e4eb2 commit dea328a
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/components/settings/settingsModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import './settingsModal.css';

import {css, cx} from '@emotion/css';
import {isEqual, noop} from 'lodash';
import React, {Fragment, useCallback, useEffect, useMemo, useState} from 'react';
import React, {Fragment, useCallback, useLayoutEffect, useMemo, useRef, useState} from 'react';
import {browser} from 'webextension-polyfill-ts';

import {isFirefox} from '../../helpers/browserHelpers';
Expand Down Expand Up @@ -47,10 +47,10 @@ export const SettingsModal = (props: SettingsModalProps) => {
const [editorHasErrors, setEditorHasErrors] = useState(false);
const [searchQuery, setSearchQuery] = useState('');
const {renderSearchResults} = useSettingsSearch();
const [isInitialRender, setIsInitialRender] = useState(true);
const isInitialRender = useRef(true);

useEffect(() => {
setIsInitialRender(false);
useLayoutEffect(() => {
isInitialRender.current = false;
}, []);

const makeOnSettingsChange = <T extends keyof BTDSettings>(key: T) => {
Expand Down Expand Up @@ -125,7 +125,7 @@ export const SettingsModal = (props: SettingsModalProps) => {
};

const renderSearchIndex = () => {
if (!isInitialRender) {
if (!isInitialRender.current) {
return null;
}

Expand Down

0 comments on commit dea328a

Please sign in to comment.