Next.js Discord

Discord Forum

Confirm that using dynamic import inside the component is ok?

Answered
Brown bear posted this in #help-forum
Open in Discord
Avatar
Brown bearOP
I need to access the props in the loading component.

'use client';

import { memo, useMemo } from 'react';
import CompStatic from './CompStatic';
import dynamic from 'next/dynamic';

type Comp = {
  data: any;
  listingId: string;
};

const Comp = ({ data, listingId }: Comp) => {
  const CompDynamic = useMemo(
    () =>
      dynamic(() => import('./CompDynamic'), {
        ssr: false,
        loading: () => <CompStatic data={data} />,
      }),
    [data]
  );

  return <CompDynamic data={data} listingId={listingId} />;
};

export default memo(Comp);
Answered by B33fb0n3
yea, it's fine šŸ‘
Btw: whatever you want to archive I am sure there are easier/better ways
View full answer

7 Replies

Answer
Avatar
@Brown bear Thanks. Care to share more?
Avatar
well... if you tell me what you are trying to archive (so exactly)?
Avatar
@B33fb0n3 well... if you tell me what you are trying to archive (so exactly)?
Avatar
Brown bearOP
O. The static one will display a rendered text, but the dynamic one got extra button can press to edit and change the text and post the changes to server if logged in.

So there is an extra form inside the dynamic one.
Added about 30kb more if not dynamically loaded