react icon indicating copy to clipboard operation
react copied to clipboard

Suspense with useTransition hook

Open xsfunc opened this issue 2 years ago • 1 comments

In each page I use Suspense with fallback for lazy loading.

const Page = lazy(() => import('./ui'))

export const SomePage = () => (
  <Suspense fallback={<Loading />}>
    <Page />
  </Suspense>
)
import nprogress from 'nprogress'
import 'nprogress/nprogress.css'

export const Loading = () => {
  useEffect(() => {
    nprogress.start()
    return () => {
      nprogress.done()
    }
  }, [])

  return null
}

It works good. When I go to some page I see progressbar while page loading. But I see only progress bar. And for good UX, it is sometimes better to show the “old” UI while the new UI is being prepared.

It's now possible with startTransition. You can read more about this case here.

I read source of atomic-react-router, but my expertise was not enough to implement this feature. Maybe you know how to do it.

xsfunc avatar Aug 05 '22 17:08 xsfunc

Cool, thanks for the info We probably need to think about adding it to the core, to make it available not only for react

Kelin2025 avatar Aug 22 '22 14:08 Kelin2025