Next.js - dynamic import vs await import

4.8k Views Asked by At

I'm wondering about the difference between dynamic import (next.js feature) and await import.
I couldn't find an explanation about the difference online.
I know that you can use dynamic import only to import React Components and not libraries.
But why should I use dynamic import and not just await import ?

thanks

1

There are 1 best solutions below

0
On BEST ANSWER

As they explain here https://nextjs.org/docs/advanced-features/dynamic-import, you should use next/dynamic when you import dynamic React components to be sure that NextJS is able to match webpack bundles to a specific dynamic call, and preload the component before rendering it.

So the answer to you question is yes, you should use Nextjs dynamic import, and not await import (btw, await import is just a way to load ES2020 dynamic imports )