Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Next.js 14 App Router using sdk-react-nextjs and Contentful #3300

Open
anandpatel opened this issue May 22, 2024 · 0 comments
Open

Next.js 14 App Router using sdk-react-nextjs and Contentful #3300

anandpatel opened this issue May 22, 2024 · 0 comments

Comments

@anandpatel
Copy link

Describe the bug
I am using the sdk-react-nextjs package with custom components. I have a carousel component that can have children. These children can only be a custom card component. The card component has 4 inputs.

When I add a carousel to my page and include a card within it, filling in the inputs, the carousel and card render correctly.

The issue occurs when I try to use dynamic data bindings from Contentful, where blog pages are stored. The card does not render any of the dynamic content.

I would like to have the carousel be client side, but the card server side. Am I using sdk-react-nextjs unnecessarily?

Expected behavior
Render card with values.

Screenshots
Builder Content

Additional context

import {
  Content,
  fetchOneEntry,
  getBuilderSearchParams,
  isEditing,
  isPreviewing,
} from '@builder.io/sdk-react-nextjs'

import { BlogCardComponent } from '@/components/destination/cards/BlogCard'
import { BlogCarouselComponent } from '@/components/destination/carousel/BlogCarousel'
import NotFound from '@/app/not-found'

interface PageProps {
  params: {
    page: string[]
  }
  searchParams: Record<string, string>
}

const BUILDER_PUBLIC_API_KEY = process.env.NEXT_PUBLIC_BUILDER_API_KEY!

export default async function Page(props: PageProps) {
  const urlPath = '/' + (props.params?.page?.join('/') || '')

  const content = await fetchOneEntry({
    model: 'page',
    apiKey: BUILDER_PUBLIC_API_KEY,
    options: getBuilderSearchParams(props.searchParams),
    userAttributes: { urlPath },
  })

  const canShowContent =
    content || isPreviewing(props.searchParams) || isEditing(props.searchParams)

  if (!canShowContent) {
    return <NotFound />
  }

  return (
    <Content
      content={content}
      model="page"
      apiKey={BUILDER_PUBLIC_API_KEY}
      customComponents={[
        BlogCardComponent,
        BlogCarouselComponent,
      ]}
    />
  )
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant