phanpy/src/components/intl-segmenter-suspense.jsx

28 lines
749 B
React
Raw Normal View History

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';
const supportsIntlSegmenter = !shouldPolyfill();
export default function IntlSegmenterSuspense({ children }) {
if (supportsIntlSegmenter) {
2024-03-27 03:09:24 +03:00
return <Suspense fallback={<Loader />}>{children}</Suspense>;
}
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 />
);
}