Ask*_*ing 0 javascript reactjs next.js
根据 NextJs 文档,我们可以对 javascript 文件使用动态导入const DynamicComponent = dynamic(() => import('../components/hello'))
。
对于这样的文件
使用动态导入也是正确的:.tsx
const MyComponent = dynamic(() => import('main/my-file.tsx'), {
ssr: false,
});
Run Code Online (Sandbox Code Playgroud)
?或者我们可以仅动态导入.js
文件?
我想你可以ts
通过一些解决方法在 nextjs 中动态导入文件。
import dynamic from "next/dynamic";
...
...
const Button = dynamic(() => import("../components/Button").then(module => module.default));
Run Code Online (Sandbox Code Playgroud)
如果您想进一步阅读https://github.com/vercel/next.js/issues/4515