Confirm that using dynamic import inside the component is ok?
Answered
Brown bear posted this in #help-forum
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
Btw: whatever you want to archive I am sure there are easier/better ways
7 Replies
@Brown bear 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);
yea, it's fine š
Btw: whatever you want to archive I am sure there are easier/better ways
Btw: whatever you want to archive I am sure there are easier/better ways
Answer
@B33fb0n3 yea, it's fine š
Btw: whatever you want to archive I am sure there are easier/better ways
Brown bearOP
Thanks. Care to share more?
@Brown bear Thanks. Care to share more?
well... if you tell me what you are trying to archive (so exactly)?
@B33fb0n3 well... if you tell me what you are trying to archive (so exactly)?
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.
So there is an extra form inside the dynamic one.
Added about 30kb more if not dynamically loaded