passing callbacks as props from Server Components into Client Components
Unanswered
Himalayan posted this in #help-forum
HimalayanOP
i have a question about next 13, if next js is encouraging us to use server components (especially for fast loading time and seo), and at the same time we can't pass callbacks from these server compos into reusable component like Button component, see exampel below :
i have 2 server components Product and Article
1-
2-
and my Button component which is client side
obviously this gives an error, while i'm concerned about SEO for my 2 previous component, so i do not want to turn them into client component,
what's best way to solve this problem and achieve good peformance and SEO friendly app
thank you for the help
i have 2 server components Product and Article
1-
export default function Product() {
const Buy = () => {
//Buy
};
return (
<Button func={Buy}></Button>
);
}2-
export default function Article() {
const AddToFav = () => {
//AddToFav
};
return (
<Button func={AddToFav}></Button>
);
}and my Button component which is client side
export const Button = ({ func }) => {
return <button onClick={func}>Click me</button>;
};obviously this gives an error, while i'm concerned about SEO for my 2 previous component, so i do not want to turn them into client component,
what's best way to solve this problem and achieve good peformance and SEO friendly app
thank you for the help
2 Replies
@Himalayan i have a question about next 13, if next js is encouraging us to use server components (especially for fast loading time and seo), and at the same time we can't pass callbacks from these server compos into reusable component like Button component, see exampel below :
i have 2 server components Product and Article
1-
export default function Product() {
const Buy = () => {
//Buy
};
return (
<Button func={Buy}></Button>
);
}
2-
export default function Article() {
const AddToFav = () => {
//AddToFav
};
return (
<Button func={AddToFav}></Button>
);
}
and my Button component which is client side
export const Button = ({ func }) => {
return <button onClick={func}>Click me</button>;
};
obviously this gives an error, while i'm concerned about SEO for my 2 previous component, so i do not want to turn them into client component,
what's best way to solve this problem and achieve good peformance and SEO friendly app
thank you for the help
Berger Picard
I think there's no enough information provided to help you.
As long as I can see from your code you could just move the function inside the component itself
As long as I can see from your code you could just move the function inside the component itself
HimalayanOP
you mean moving all functions into our reusable comopnent ? in this case moving both AddToFav() and Buy() into Button component ?,isn't that bad practice ?