'use client' leading to Maximum call stack size exceeded
Unanswered
Goldstripe sardinella posted this in #help-forum
Goldstripe sardinellaOP
I want to add an onClick functionality to this component, but when I add the 'use Client' , I encounter this error. I am using this component inside the server side component.
21 Replies
Goldstripe sardinellaOP
import ThreadCard from "@/components/cards/ThreadCard";
import { fetchPosts } from "@/lib/actions/thread.action";
import { currentUser } from '@clerk/nextjs'
const Page = async ()=> {
const user = await currentUser()
const result = await fetchPosts(1, 30)
// console.log("result ", result);
const handleLikeClick = ()=>{
console.log("Like");
}
return (
<>
<h1 className="head-text text-left" > Home</h1>
<section className="mt-9 flex flex-col gap-10" >
{
result.posts.length === 0 ? (
<p className="no-result" >No threads found</p>
) : (
<>
{
result.posts.map((post)=>(
<ThreadCard key={post._id} id={post._id.toString()} parentId={post.parentId} content={post.text} author={post.author} community={post.community} createdAt = {post.createdAt} comments={post.children} currentUserId={user?.id || ""} handleLikeClick={handleLikeClick} ></ThreadCard>
))
}
</>
)
}
</section>
</>
)
}Giant panda
For the future please format code like this:
```ts
Code here
```
```ts
Code here
```
Also, you can't pass down event handlers (or functions for that matter) from server components to client components which is one possible cause for the cryptic error.
Goldstripe sardinellaOP
if i remove the handler still i am getting same problem
@Giant panda For the future please format code like this:
\`\`\`ts
Code here
\`\`\`
Goldstripe sardinellaOP
okk
page.tsx
import ThreadCard from "@/components/cards/ThreadCard";
import { fetchPosts } from "@/lib/actions/thread.action";
import { currentUser } from '@clerk/nextjs'
const Page = async ()=> {
const user = await currentUser()
const result = await fetchPosts(1, 30)
// console.log("result ", result);
return (
<>
<h1 className="head-text text-left" > Home</h1>
<section className="mt-9 flex flex-col gap-10" >
{
result.posts.length === 0 ? (
<p className="no-result" >No threads found</p>
) : (
<>
{
result.posts.map((post)=>(
<ThreadCard key={post._id} id={post._id.toString()} parentId={post.parentId} content={post.text} author={post.author} community={post.community} createdAt = {post.createdAt} comments={post.children} currentUserId={user?.id || ""} ></ThreadCard>
))
}
</>
)
}
</section>
</>
)
}
export default Page Giant panda
And your ThreadCard component's code?
Goldstripe sardinellaOP
if i remove 'use client ' my project is running fine
Goldstripe sardinellaOP
@Giant panda sorry to bother you. Could you please give me some suggestions? I'm so frustrated, and I don't know why this simple thing is not working.
Goldstripe sardinellaOP
solved.
@Goldstripe sardinella solved.
Reddish carpenter ant
Hello, I may be running into a similar issue, how did you manage to resolve it?
@Goldstripe sardinella solved.
American black bear
I might be having the same issue. How did you resolve it?
Whiteleg shrimp
The fact that it happens inside a string.replace makes me think a function was being used for replacement and that it was, itself calling string replace or something. Not sure if this has a lot to do with "use client"