From 29e86590d1e89f51215ef570b9888b0661f96197 Mon Sep 17 00:00:00 2001 From: Patrik Korytar Date: Tue, 2 Jul 2024 16:38:36 +0200 Subject: [PATCH] NCL-6996 Remove ReactDOM.unstable_batchedUpdates calls --- src/hooks/useServiceContainer.ts | 39 ++++++++++++-------------------- 1 file changed, 15 insertions(+), 24 deletions(-) diff --git a/src/hooks/useServiceContainer.ts b/src/hooks/useServiceContainer.ts index d560fa23..57eae45a 100644 --- a/src/hooks/useServiceContainer.ts +++ b/src/hooks/useServiceContainer.ts @@ -1,6 +1,5 @@ import { AxiosError, AxiosRequestConfig, AxiosResponse, isAxiosError } from 'axios'; import { Dispatch, SetStateAction, useCallback, useEffect, useRef, useState } from 'react'; -import ReactDOM from 'react-dom'; import { backendErrorMessageMapper } from 'common/backendErrorMessageMapper'; @@ -132,22 +131,18 @@ export const useServiceContainer = )(requestConfig) ) .then((response) => { - // In a future React version (potentially in React 17) this could be removed as it will be default behavior - // https://stackoverflow.com/questions/48563650/does-react-keep-the-order-for-state-updates/48610973#48610973 - ReactDOM.unstable_batchedUpdates(() => { - setLoading(false); - - /** - * Convert undefined to {@link DataValues.noData} as - * undefined is reserved for {@link DataValues.notYetData} - */ - if (response.data === undefined) { - setData(DataValues.noData); - } else { - setData(response.data); - } - setError(ERROR_INIT); - }); + setLoading(false); + + /** + * Convert undefined to {@link DataValues.noData} as + * undefined is reserved for {@link DataValues.notYetData} + */ + if (response.data === undefined) { + setData(DataValues.noData); + } else { + setData(response.data); + } + setError(ERROR_INIT); return response; }) @@ -157,13 +152,9 @@ export const useServiceContainer = { - setLoading(false); - setError(errorMessage); - setData(DataValues.noData); - }); + setLoading(false); + setError(errorMessage); + setData(DataValues.noData); } }