Skip to content

Commit

Permalink
updating component is mounted check
Browse files Browse the repository at this point in the history
  • Loading branch information
jgowdyelastic committed Jan 19, 2021
1 parent bd0ae2d commit 6f1867d
Showing 1 changed file with 4 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* you may not use this file except in compliance with the Elastic License.
*/

import React, { FC, useEffect, useCallback, useState } from 'react';
import React, { FC, useEffect, useCallback, useState, useRef } from 'react';
import { i18n } from '@kbn/i18n';

import {
Expand Down Expand Up @@ -50,16 +50,16 @@ export const ModelSnapshotTable: FC<Props> = ({ job, refreshJobList }) => {
const [closeJobModalVisible, setCloseJobModalVisible] = useState<ModelSnapshot | null>(null);
const [combinedJobState, setCombinedJobState] = useState<COMBINED_JOB_STATE | null>(null);

let unmounted = false;
const isMounted = useRef(true);
useEffect(() => {
loadModelSnapshots();
return () => {
unmounted = true;
isMounted.current = false;
};
}, []);

async function loadModelSnapshots() {
if (unmounted === true) {
if (isMounted.current === false) {
// table refresh can be triggered a while after a snapshot revert has been triggered.
// ensure the table is still visible before attempted to refresh it.
return;
Expand Down

0 comments on commit 6f1867d

Please sign in to comment.