Ask · Answer · Grow
A community platform for Software Engineers to ask questions, share knowledge, and grow together.
3 questions in the community
මම Next.js 14 App Router පාවිච්චි කරලා "Dashboard" එකක් හදනවා. ඒකේ User ගේ Profile එකේ දත්ත පෙන්වන්න මම useEffect සහ fetch පාවිච්චි කරනවා. හැබැයි මට ප්රශ්න දෙකක් තියෙනවා: පිටුව Load වෙද්දී දත්ත එනකන් මුකුත් පේන්නේ නැහැ, ඒක නිසා User ට හිතෙන්නේ App එක වැඩ කරන්නේ නැහැ කියලා. සමහර වෙලාවට මට "Hydration failed" error එකක් එනවා මම Client-side එකේ විතරක් තියෙන දත්ත (LocalStorage වගේ) Render කරන්න හැදුවොත්. මගේ දැනට තියෙන Code එක: 'use client'; import { useState, useEffect } from 'react'; export default function Profile() { const [user, setUser] = useState(null); useEffect(() => { fetch('/api/user') .then(res => res.json()) .then(data => setUser(data)); }, []); // දත්ත එනකන් මේක හිස්ව පේනවා (Empty screen) if (!user) return null; return <div>Welcome, {user.name}!</div>; } මට දැනගන්න අවශ්ය දේ: දත්ත එනකන් User ට ලස්සනට "Loading State" එකක් (Skeleton Loader එකක් වගේ) පෙන්වන්නේ කොහොමද? Next.js වල Suspense පාවිච්චි කරලා මේක මීට වඩා හොඳට කරන්න පුළුවන්ද? Server-side එකේදීම මේ දත්ත ටික අරගෙන පෙන්වන එක (Server Components) මීට වඩා හොඳද?
My Current Schema: Code snippet model Answer { id String @id @default(uuid()) content String codeSnippet String? authorId String // Foreign key to User model questionId String createdAt DateTime @default(now()) } My Current Server Action: // app/actions.ts export async function deleteAnswer(answerId: string) { // Problem: This doesn't check WHO is making the request await prisma.answer.delete({ where: { id: answerId } }); revalidatePath('/question/[id]'); } What I need: How do I conditionally render the Edit/Delete buttons in the UI only for the owner? How do I secure the Server Action so a malicious user can't trigger it via the console using someone else's answerId?
Hi everyone, I'm trying to access localStorage inside a useEffect in my Next.js 14 project, but I keep getting a 'Hydration failed' error. I've tried checking if window is defined, but it still happens occasionally. Any ideas on how to fix this properly in the App Router?
Showing all 3 questions