2024-03-25 14:31:25 +03:00
|
|
|
import { shouldPolyfill } from '@formatjs/intl-segmenter/should-polyfill';
|
|
|
|
import { Suspense } from 'preact/compat';
|
|
|
|
import { useEffect, useState } from 'preact/hooks';
|
|
|
|
|
2024-03-27 03:09:24 +03:00
|
|
|
import Loader from './loader';
|
|
|
|
|
2024-03-25 14:31:25 +03:00
|
|
|
const supportsIntlSegmenter = !shouldPolyfill();
|
|
|
|
|
|
|
|
export default function IntlSegmenterSuspense({ children }) {
|
|
|
|
if (supportsIntlSegmenter) {
|
2024-03-27 03:09:24 +03:00
|
|
|
return <Suspense fallback={<Loader />}>{children}</Suspense>;
|
2024-03-25 14:31:25 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
const [polyfillLoaded, setPolyfillLoaded] = useState(false);
|
|
|
|
useEffect(() => {
|
|
|
|
(async () => {
|
|
|
|
await import('@formatjs/intl-segmenter/polyfill-force');
|
|
|
|
setPolyfillLoaded(true);
|
|
|
|
})();
|
|
|
|
}, []);
|
|
|
|
|
2024-03-27 03:09:24 +03:00
|
|
|
return polyfillLoaded ? (
|
|
|
|
<Suspense fallback={<Loader />}>{children}</Suspense>
|
|
|
|
) : (
|
|
|
|
<Loader />
|
|
|
|
);
|
2024-03-25 14:31:25 +03:00
|
|
|
}
|