隔壁
隔壁老王楼主
Next.js Server Action 返回 undefined,可能是 Action 函数没有 return 值,或 return 的对象结构不对。Server Action 应该返回 { success: boolean, data?: T, error?: string } 格式。
Prisma 乐观锁并发更新冲突,用 $executeRaw 原子更新:UPDATE table SET count = count + 1 WHERE id = $1 AND count < $limit。配合 FOR UPDATE 行锁防并发竞争。
React Server Component 中使用 useState 报错,因为 Server Component 不能用 hooks。解决:① 把需要状态的组件拆成 Client Component(加 'use client') ② 父组件保持 Server Component 做数据获取,子组件 Client 做交互。