0

HERE ERROR IMAGE

export const Filter = async (): Promise<JSX.Element> => { const { data: categories } = await api.get('/categories/') return ( <div className='w-full h-full relative'> <Container className='sticky top-[6rem] max-lg:col-span-2'> <div className='grid grid-cols-1 gap-6 max-h-[40rem] overflow-y-scroll overflow-hidden'> There is the problem i think <Container className='flex items-center flex-col'> <SmallHeading>Kategoria</SmallHeading> <ul className='grid grid-cols-1 gap-4 max-h-[25rem] overflow-y-scroll overflow-hidden w-full'> {categories.map(c => { return <CategoryItem key={c.id} href={c.name} name={c.name} image={c.img} isSmall={true} /> })} </ul> </Container> </div> </Container> </div> ) } 

'Filter' cannot be used as a JSX component. Its return type 'Promise' is not a valid JSX element. Type 'Promise' is missing the following properties from type 'ReactElement<any, any>': type, props, key

Help i'll try everythink

I tried what is in the code I gave above, I don't understand why such an error appear

    4 Answers 4

    2

    I think you can use async components only in app directory. From the next13 docs

    This new data fetching model is currently being developed by the React team. We recommend reading the support for promises React RFC which introduces async/await in Server Components and a new use() hook for client components. While you can try it out, it is not yet stable. We'll keep these docs updated to reflect the latest developments.

    Warning: You can use async/await in layouts and pages, which are Server Components. Using async/await inside other components, with TypeScript, can cause errors from the response type from JSX. We are working with the TypeScript team to resolve this upstream. As a temporary workaround, you can use {/* @ts-expect-error Server Component */} to disable type checking for the component.

      0

      For people like me, who did not know "use client" also prevent fetch components.

        0

        I was having the same issue removing "use client" from the component solved the issue. so, don't use use async await in a client component in Next.js

          0

          Update eslint-config-next package to the latest version maybe resolve that issue

          1
          • As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.
            – CommunityBot
            CommentedMay 13, 2024 at 22:28

          Start asking to get answers

          Find the answer to your question by asking.

          Ask question

          Explore related questions

          See similar questions with these tags.