🐛 fix(tabsContext.tsx): add delay to refreshFlows function to prevent race condition with API call
🐛 fix(typesContext.tsx): add delay to useEffect to prevent race condition with API call
This commit is contained in:
parent
1ed89cbbad
commit
1f42910c55
2 changed files with 16 additions and 9 deletions
|
|
@ -113,16 +113,18 @@ export function TabsProvider({ children }: { children: ReactNode }) {
|
|||
}
|
||||
|
||||
function refreshFlows() {
|
||||
getTabsDataFromDB().then((DbData) => {
|
||||
if (DbData && Object.keys(templates).length > 0) {
|
||||
try {
|
||||
processDBData(DbData);
|
||||
updateStateWithDbData(DbData);
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
setTimeout(() => {
|
||||
getTabsDataFromDB().then((DbData) => {
|
||||
if (DbData && Object.keys(templates).length > 0) {
|
||||
try {
|
||||
processDBData(DbData);
|
||||
updateStateWithDbData(DbData);
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
}, 2000);
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
|
|
|
|||
|
|
@ -39,6 +39,9 @@ export function TypesProvider({ children }: { children: ReactNode }) {
|
|||
const { setLoading } = useContext(alertContext);
|
||||
|
||||
useEffect(() => {
|
||||
|
||||
setTimeout(() => {
|
||||
|
||||
// We will keep a flag to handle the case where the component is unmounted before the API call resolves.
|
||||
let isMounted = true;
|
||||
|
||||
|
|
@ -85,6 +88,8 @@ export function TypesProvider({ children }: { children: ReactNode }) {
|
|||
}
|
||||
|
||||
getTypes();
|
||||
}, 2000);
|
||||
|
||||
}, []);
|
||||
|
||||
function deleteNode(idx: string) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue