-
Notifications
You must be signed in to change notification settings - Fork 27k
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
useMemo problem in Next js when using contentlayer #49267
Comments
(Deleted as it was misleading) |
For me, a similar error happens only when deployed to Vercel, for useEffect: |
I think this is related to #49261 |
useMemo is pointless in server components because it does not re-render at all anyway.
export const useMDXComponent = (code: string, globals: Record<string, unknown> = {}) => {
return React.useMemo(() => getMDXComponent(code, globals), [code, globals])
} import { allPosts } from 'contentlayer/generated'
import { getMDXComponent } from 'next-contentlayer/hooks'
import { notFound } from 'next/navigation'
export function generateStaticParams() {
return allPosts.map((post) => ({
slug: post._raw.flattenedPath,
}))
}
export default async function Page({ params }) {
// Find the post for the current page.
const post = allPosts.find((post) => post._raw.flattenedPath === params.slug)
// 404 if the post does not exist.
if (!post) notFound()
// Parse the MDX file via the getMDXComponent.
const MDXContent = getMDXComponent(post.body.code)
return (
<div>
{/* Some code ... */}
<MDXContent />
</div>
)
} |
Oh, thanks! It works. |
This closed issue has been automatically locked because it had no new activity for a month. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you. |
Verify canary release
Provide environment information
Which area(s) of Next.js are affected? (leave empty if unsure)
No response
Link to the code that reproduces this issue
https://github.com/RajinCoding2007/Next-ContentLayer-Bug
To Reproduce
I followed contentlayer documentation and used
useMDXComponent(post.body.code)
to render markdown file and it causes error.Describe the Bug
I was following contentlayer documentation, I got this error:
Expected Behavior
I expected that MDX page will be rendered successfully. I also made an issue in contentlayer repo:
contentlayerdev/contentlayer#449
Which browser are you using? (if relevant)
Chrome
How are you deploying your application? (if relevant)
No response
The text was updated successfully, but these errors were encountered: