Passing props to server children
Unanswered
Sun bear posted this in #help-forum
Sun bearOP
So my page is structured like this:
I get an error for passing props to the nested ServerComponent for some reason I don't understand.
⨯ Error: Functions cannot be passed directly to Client Components unless you explicitly expose it by marking it with "use server".
[function, function]
^^^^^^^^
at stringify (<anonymous>)
I could really need some help with this. Thanks
import ClientComponent from './client-component'
import ServerComponent from './server-component'
export default async function Page() {
const projects = await getProjects()
return (
<div>
{projects.map((project, index) => {
return (<ClientComponent>
<ServerComponent project= {projects[index]} />
</ClientComponent>
)}
}
</div>
)
}I get an error for passing props to the nested ServerComponent for some reason I don't understand.
⨯ Error: Functions cannot be passed directly to Client Components unless you explicitly expose it by marking it with "use server".
[function, function]
^^^^^^^^
at stringify (<anonymous>)
I could really need some help with this. Thanks
6 Replies
Chinese Egret
2 things:
1. Seems like a project is some kind of function
2. Why do you use ‘projects[index]’?
1. Seems like a project is some kind of function
2. Why do you use ‘projects[index]’?
Sun bearOP
Sorry, projects is data I get from a CMS. It's just an array of objects with data inside like {title, photo, description} etc.
Chinese Egret
What does server component render?
@Sun bear So my page is structured like this:
import ClientComponent from './client-component'
import ServerComponent from './server-component'
export default async function Page() {
const projects = await getProjects()
return (
<div>
{projects.map((project, index) => {
return (<ClientComponent>
<ServerComponent project= {projects[index]} />
</ClientComponent>
)}
}
</div>
)
}
I get an error for passing props to the nested ServerComponent for some reason I don't understand.
⨯ Error: Functions cannot be passed directly to Client Components unless you explicitly expose it by marking it with "use server".
[function, function]
^^^^^^^^
at stringify (<anonymous>)
I could really need some help with this. Thanks
What is <ServerComponent> ? seems like you passed something to client component where you shouldnt
Sun bearOP
The ServerComponent renders an Image or a PortableText from the project prop I pass to it. They are just slides
The ClientComponent has the logic to animate those slides on click, touch or wheel events.
My goal was to wrap the project slides and keep them as RSC while wrapping them as children to a ClientComponent which you can think of as a kind of Carousel.
The ClientComponent has the logic to animate those slides on click, touch or wheel events.
My goal was to wrap the project slides and keep them as RSC while wrapping them as children to a ClientComponent which you can think of as a kind of Carousel.
Sun bearOP
Okay, I changed the structure of the component by fetching the projects in a parent component and pass it the the Page component. The error doesn't appear anymore.