Let's say I am using the Carousel and Carousel.Item from react-bootstrap. This can only be rendered on the client side.
I want to transform the data on my server into HTML, but still I do not want to render the component on the server side.
Why do I want to do it this way? To improve SEO of the website.
const data = [1,2,3,4];
// I want this to be rendered on the server and return
const items = data.map(i => <Carousel.Item>i</Carousel.Item>);
// I want this to return to the client and the client should be responsible of rendering the Carousel.
/*
// <Carousel>
// <Carousel.Item>1</Carousel.Item>
// <Carousel.Item>2</Carousel.Item>
// <Carousel.Item>3</Carousel.Item>
// <Carousel.Item>4</Carousel.Item>
// </Carousel>
*/
return <Carousel>{items}</Carousel>
client components are first rendered on the server. if your component has client side api functions (useState, useEffect, onClick), since those functions are not available on the server, your component will throw an error. by using
use client
it just says ignore those api, send this to client and client will take care of. that is what hydration is