5 Things in a Server Action in NextJS

A common pattern in a server action

Lately, my learning path has been illuminated by an incredible Udemy course on NextJS (Shout out to amazing instructor, Stephen Grider). I'm incredibly thankful for the resources at my disposal: access to high-quality learning materials, a quiet co-working space near my home, and the luxury of dedicated study time.

The Humbling Reality of Continuous Learning

Just when I thought I had NextJS figured out, the course quickly revealed the depths of my misunderstanding. The latest NextJS 15 version has brought significant changes that demand careful attention and review. Each module is a reminder that in the world of web development, learning is a perpetual process.

Unpacking Server Actions: A Comprehensive Approach

In my latest exploration guided by the instructor, I'm learning about server actions triggered by form submissions in detail:

  1. Field-level validation with zod library
  2. Form-level validation using next-auth's session object
  3. DB update inside a try-catch block with a prisma client (the auto-generated types provide an extra layer of type safety)
  4. Implement strategic caching with revalidatePath from next/cache
  5. Redirect the user to the most appropriate place

The Art of Asking Better Questions

With each video in the course, I'm not just learning technical skills -- I'm developing a more nuanced approach to problem-solving. Questions I never thought to ask are now becoming central to my understanding of web development.