Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

351
Visualizações
How can I dynamically import in a NextJs page data (array) not entire component

Hi all I followed the next tutorial https://nextjs.org/docs/advanced-features/dynamic-import and works great for components

But I need to fetch data dynamically. Situation:

I have one simple component named MyItems that receives as props items which is a list of elements title, category.

I want to dynamically import these lists from typescript files stored in page-data/myitems/de|en.ts and so on

So these ts files export array after doing some calculations that is why i don't import json dynamically or search for other solution. I need them to have code and export an array export default [{name: 'somename', title: somemagic()]

I have this page in pages/page

const Page = async ({ t, ...props }: Props) => {
    const locale = props._nextI18Next.initialLocale;
 

    const items = (await import(`../page-data/myitems/${locale}`)).default;
    console.log(items); // HERE I SEE OUTPUT FINE

    return (
        <>
            <Head>
                <title>dynamic test</title>
            </Head>
            {/*@ts-ignore*/}
            <MyPage items={items} />
        </>
    );
};

The error I get is that cannot return promise to react So my understanding is that I cannot export async component.

Error: Objects are not valid as a React child (found: [object Promise]). If you meant to render a collection of children, use an array instead.

That is all fine, so my question is howcan I solve this situation then ?

The goal is still the same (items are fetched fine now but the component is returned as promise due to async and rest of react magic fails)

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda