Skip to content
Discussion options

You must be logged in to vote

Hi @khayden73

ClientPost.tsx

'use client'

import { useEffect, useState } from 'react'

type Props = { slug: string }

export default function ClientPost({ slug }: Props) {
  const [MDX, setMDX] = useState<React.ComponentType | null>(null)

  useEffect(() => {
    let cancelled = false

    ;(async () => {
      const mod = await import(`@/content/${slug}.mdx`)
      if (!cancelled) setMDX(() => mod.default) // : function wrapper
    })()

    return () => {
      cancelled = true
    }
  }, [slug])

  if (!MDX) return <p>loading...</p>

  return <MDX />
}

app/blog/[slug]/page.tsx

import ClientPost from './ClientPost'

export default async function Page({ params }: { params: Promise<{ slug: 

Replies: 3 comments 1 reply

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@khayden73
Comment options

Answer selected by khayden73
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Help
Labels
None yet
3 participants