Skip to content

Commit 992f2f8

Browse files
author
Lingxi Chen
committed
fixing error
Signed-off-by: Lingxi Chen <[email protected]>
1 parent 0500f93 commit 992f2f8

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

public/pages/WorkloadManagement/WLMCreate/WLMCreate.tsx

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* SPDX-License-Identifier: Apache-2.0
44
*/
55

6-
import React, { useEffect, useState, useContext } from 'react';
6+
import React, { useEffect, useState, useContext, useRef } from 'react';
77
import {
88
EuiTitle,
99
EuiSpacer,
@@ -53,6 +53,7 @@ export const WLMCreate = ({
5353
(memThreshold != null && memThreshold > 0 && memThreshold <= 100));
5454
const [loading, setLoading] = useState(false);
5555
const { dataSource, setDataSource } = useContext(DataSourceContext)!;
56+
const isMounted = useRef(true);
5657

5758
useEffect(() => {
5859
core.chrome.setBreadcrumbs([
@@ -68,6 +69,12 @@ export const WLMCreate = ({
6869
]);
6970
}, [core.chrome, history]);
7071

72+
useEffect(() => {
73+
return () => {
74+
isMounted.current = false;
75+
};
76+
}, []);
77+
7178
const handleCreate = async () => {
7279
setLoading(true);
7380
try {
@@ -102,14 +109,17 @@ export const WLMCreate = ({
102109

103110
core.notifications.toasts.addSuccess(`Workload group "${name}" created successfully.`);
104111
history.push('/workloadManagement');
112+
return;
105113
} catch (err) {
106114
console.error(err);
107115
core.notifications.toasts.addDanger({
108116
title: 'Failed to create workload group',
109117
text: err?.body?.message || 'Something went wrong',
110118
});
111119
} finally {
112-
setLoading(false);
120+
if (isMounted.current) {
121+
setLoading(false);
122+
}
113123
}
114124
};
115125

0 commit comments

Comments
 (0)