real time fetching on server component
Unanswered
Scaly-naped Pigeon posted this in #help-forum
Scaly-naped PigeonOP
I wanted to code something that render an initial data and then get real time updates from database but when I use EventSource in nextjs its a client component I have to use useState to save and render new data also websockets is requires client components so is there anyway I can use EventSource in server component or is there anyother way without revalidate new data ?
I wanted to use nextjs server component to lower data fetching from database also to make this page fast
export default async function Page() {
const events = new EventSource(
${process.env.NEXT_PUBLIC_SERVER}/new-data, { withCredentials: true });
events.onmessage = (e) => {
const sourceData: NewTypes= JSON.parse(e.data);
};
}
I wanted to use nextjs server component to lower data fetching from database also to make this page fast