diff --git a/.changeset/lovely-bats-chew.md b/.changeset/lovely-bats-chew.md new file mode 100644 index 000000000..aff4c4977 --- /dev/null +++ b/.changeset/lovely-bats-chew.md @@ -0,0 +1,5 @@ +--- +"@scaleway/use-i18n": patch +--- + +Remove usage of unstable_batch_update from react-dom as it's default behavior of react now diff --git a/packages/use-i18n/src/usei18n.tsx b/packages/use-i18n/src/usei18n.tsx index ab424993d..2b17229e7 100644 --- a/packages/use-i18n/src/usei18n.tsx +++ b/packages/use-i18n/src/usei18n.tsx @@ -16,7 +16,6 @@ import { useMemo, useState, } from 'react' -import ReactDOM from 'react-dom' import dateFormat, { type FormatDateOptions } from './formatDate' import unitFormat, { type FormatUnitOptions } from './formatUnit' import formatters, { type IntlListFormatOptions } from './formatters' @@ -292,22 +291,15 @@ const I18nContextProvider = ({ ...result[currentLocale]?.default, } - // avoid a lot of render when async update - // This is handled automatically in react 18, but we leave it here for compat - // https://github.com/reactwg/react-18/discussions/21#discussioncomment-801703 - ReactDOM.unstable_batchedUpdates(() => { - setTranslations(prevState => ({ - ...prevState, - ...{ - [currentLocale]: { - ...prevState[currentLocale], - ...trad, - }, - }, - })) - - setNamespaces(prevState => [...new Set([...prevState, namespace])]) - }) + setTranslations(prevState => ({ + ...prevState, + [currentLocale]: { + ...prevState[currentLocale], + ...trad, + }, + })) + + setNamespaces(prevState => [...new Set([...prevState, namespace])]) return namespace },