0

According NextJs documentation we can use dynamic import for javascripts filesconst DynamicComponent = dynamic(() => import('../components/hello')).
Will be correct to use dynamic import also for .tsx file like this:

const MyComponent = dynamic(() => import('main/my-file.tsx'), {
  ssr: false,
});

? Or we can import dynamically only .js files?

1
  • You can dynamically import both JavaScript and TypeScript modules. Commented Apr 1, 2022 at 22:23

1 Answer 1

5

I guess you can dynamically import ts files in nextjs with some workarounds.

import dynamic from "next/dynamic";
...
...
const Button = dynamic(() => import("../components/Button").then(module => module.default));

If you want to read further https://github.com/vercel/next.js/issues/4515

Sign up to request clarification or add additional context in comments.

1 Comment

but in the way i wrote will work> Because i tried and looks ok like i did.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.