Next.js Discord

Discord Forum

TypeError: Cannot destructure property 'params' of 'param' as it is undefined.

Unanswered
Beveren posted this in #help-forum
Open in Discord
BeverenOP
I get this when trying to destructure and pass on a property using the app page router.
It works sometimes, but changing between the param paths will give me this error in this file:

/src/app/[floor]/page.tsx

'use client'
import useSWR from 'swr'
import SearchInput from '@/components/Search/SearchInput'
import FloorPlan from '@/components/FloorPlan/FloorPlan'
interface Props {
    params: { floor: string }
}

const fetcher = (url: URL) => fetch(url).then(res => res.json())

const Home = async ({ params: { floor } }: Props) => {
    const { data, error } = useSWR('/api/staticdata', fetcher)

    // Handle the error state
    if (error) return <div>Failed to load</div>

    // Handle the loading state
    if (!data) return <div>Loading...</div>

    return(
      <main>
            <SearchInput data={data} />
            <FloorPlan floor={floor} />
      </main>
    )
}

export default Home

3 Replies

Giant panda
A client component cannot be async
Not sure if it's related to your issue, but it's definitely wrong and can cause errors
BeverenOP
It seems to make it work by removing 'async', will have to test it more. Thanks!