Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

350
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!