Skip to content

Suspense with useTransition hook #4

@xsfunc

Description

@xsfunc

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions