Data & Forms Review, Practice & Interview Prep
Summary
Section titled “Summary”Key Takeaways
Section titled “Key Takeaways”Section 13 — Database Integration
Section titled “Section 13 — Database Integration”- Next.js accesses databases only from the server (Server Components, Route Handlers, Server Actions)
- Use Prisma for type-safe relational databases (PostgreSQL, MySQL); use Mongoose for MongoDB; use Drizzle for lightweight SQL
- Always use a singleton client — never instantiate
PrismaClientper request - Store credentials in
.env.local, never in code - Use transactions for operations that must succeed or fail together
- Index columns you filter or sort by frequently
- Always paginate queries — never fetch all records
Section 14 — State Management
Section titled “Section 14 — State Management”- Local state (
useState,useReducer) for component-level concerns - Context API for small-medium global state (theme, auth) — but split contexts by update frequency
- Redux Toolkit for large-scale apps needing DevTools, time-travel, and team-friendly patterns
- Zustand for simple, boilerplate-free global state
- TanStack Query for all server/async data — it handles caching, deduplication, background refetching automatically
- Don’t put server data in Redux — use TanStack Query instead
Section 15 — Forms & Validation
Section titled “Section 15 — Forms & Validation”- React Hook Form + Zod is the modern standard for form handling in Next.js
- Always validate on both client AND server
- Share Zod schemas between client and server for a single source of truth
- Use Server Actions with
useActionStatefor progressive enhancement - Never trust client-provided file types — validate on the server
- Always consider accessibility (labels, aria-*, role=“alert”)
Practice Exercises
Section titled “Practice Exercises”Beginner
Section titled “Beginner”- Build a contact form with React Hook Form + Zod validation (name, email, message)
- Create a theme switcher using Context API (light/dark)
- Connect to MongoDB and create a User model with Mongoose
- Build a simple Todo CRUD with Prisma + PostgreSQL
Intermediate
Section titled “Intermediate”- Build a shopping cart with Zustand that persists to localStorage
- Create a paginated list of blog posts fetched with TanStack Query
- Build a multi-step registration form (3 steps) with React Hook Form
- Implement file upload with validation (type + size) on both client and server
Advanced
Section titled “Advanced”- Build an authentication system with JWT + Prisma (login, register, refresh tokens)
- Implement optimistic updates in a todo app with TanStack Query
- Create a normalized Redux state for a social feed (users, posts, likes)
- Build a product management form with image upload, tags (many-to-many), and full server-side validation
Mini Project Ideas
Section titled “Mini Project Ideas”1. Blog Application
Section titled “1. Blog Application”Covers: Prisma + PostgreSQL, TanStack Query, React Hook Form
- User auth (login/register)
- Create/edit/delete posts (rich text)
- Tags (many-to-many relationship)
- Comments with nested replies
- Pagination and search
- Admin dashboard for content moderation
2. Task Management App
Section titled “2. Task Management App”Covers: Zustand or Redux Toolkit, Prisma, Multi-step forms
- Drag-and-drop Kanban board
- Task CRUD with priorities and due dates
- Team collaboration (share boards)
- File attachments
- Real-time updates with TanStack Query polling
- Statistics dashboard
3. E-Commerce Backend
Section titled “3. E-Commerce Backend”Covers: PostgreSQL + Prisma, complex schema design, transactions
- Product catalog with categories and variants
- Inventory management
- Shopping cart with Zustand
- Order processing with database transactions
- Payment webhook handling
- Admin product management forms with image upload
4. Admin Dashboard
Section titled “4. Admin Dashboard”Covers: All three sections combined
- Data tables with server-side pagination/sorting/filtering
- Charts with TanStack Query for live data
- Role-based access control (RBAC) with Prisma
- Bulk operations with transactions
- Export (CSV/PDF) functionality
- Complex filter forms with many fields
Interview Preparation
Section titled “Interview Preparation”Beginner Questions
Section titled “Beginner Questions”- What is an ORM and why would you use one?
- What is the difference between
useStateanduseReducer? - What is controlled vs uncontrolled form input in React?
- How do you connect a Next.js app to MongoDB?
- What is Context API and when would you use it?
- What is Zod and how does it help with validation?
- Why should you validate form data on the server?
Intermediate Questions
Section titled “Intermediate Questions”- Explain the N+1 query problem and how to solve it with Prisma
- How does Redux Toolkit differ from traditional Redux?
- What is connection pooling and why is it important?
- How do React Hook Form and Zod work together?
- When would you choose TanStack Query over Redux for data fetching?
- Explain database transactions and give an example use case
- How do you implement pagination in Prisma?
- What is
persistmiddleware in Zustand?
Advanced Questions
Section titled “Advanced Questions”- How would you design a scalable database schema for a multi-tenant SaaS app?
- What are the tradeoffs between Context API and state management libraries?
- How do you prevent race conditions in concurrent form submissions?
- Explain database indexing strategies and their performance implications
- How would you implement real-time data sync in a Next.js + database app?
- Describe how you’d handle optimistic UI updates with rollback on error
- How do Server Actions change the way we handle forms compared to API routes?
- What is state normalization and when is it necessary?
- How would you design an audit log system using database transactions?
- Explain how TanStack Query handles cache invalidation and stale data
Next Up: Part 4 — Authentication, Deployment, Performance Optimization, and Testing
Previous: Part 3A — API Routes, Middleware, and Authentication Basics
Documentation by Next.js Deep Dive Series | Last updated: 2024 | Next.js 14+ App Router