is fetching data in client components like this a bad practice?
Answered
Pacific sand lance posted this in #help-forum
Pacific sand lanceOP
or should I be fetching from api endpoints instead? see the below code:
useEffect(() => {
const fetchData = async () => {
try {
const userId = user.session?.id
const fetchedUser = await prisma.user.findUnique({
where: { id: userId },
});
setUser(fetchedUser);
} catch (err) {
setError(err);
}
};
fetchData();
}, []);Answered by riský
you should use server components, and if not possible then server actions/ api endpoints to preserve the querying on sever