Neon can use client component, but not local postgres? - next14,postgres,drizzle -
Hi,
how to re-create this use-effect using a server component?
useEffect(() => {
const fetchNotifications = async () => {
if (email) {
const user = await getUserByEmail(email);
if (user) {
const unreadNotifications = await getUnreadNotifications(user.id);
setNotifications(unreadNotifications);
}
}
};
fetchNotifications();
const notificationInterval = setInterval(fetchNotifications, 30000); // Poll every 30 seconds
return () => clearInterval(notificationInterval);
}, [email]);
thanks.
4 Replies
well you can place fetchNotifications in a server action or server-only file to do it in server component
server actions are the right way considering you will need email from client side in a form
was thinking also to refetch or revalidate. like cache in react-query
or knocklabs
React in-app notifications example | Powered by Knock
In-app notification feed and toasts, powered by Knock
If you revalidate a page it will update for all the users who visit that page. Either make page url unique for users or use tags