A
A
Andrey Okhotnikov2019-05-16 11:03:20
React
Andrey Okhotnikov, 2019-05-16 11:03:20

How to work with lazy loading in Nextjs React?

When developing on pure react, I can set the lazy loading of components in the router like this

const NotFoundPage = lazy(() => import('containers/NotFoundPage'));
const HomePage = lazy(() => import('containers/HomePage'));
const Stores = lazy(() => import('containers/StoresPage'));

export default () => (
 <Router>
        <Suspense fallback={<Preloader />}>
          <Switch>
            <Route exact path={routes.HOME} component={HomePage} />
            <Route exact path={routes.STORES} component={Stores} />
            <Route component={NotFoundPage} />
          </Switch>
        </Suspense>
      </Router>
);

And how to work with lazy loading in Next js (began to deal with SSR). How does it even work there?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question