React / Next.js

Server Actions ของ Next.js

Server Actions, useFormState, useFormStatus, mutations, การปรับปรุงแบบก้าวหน้า, การตรวจสอบใหม่

20 คำถามสัมภาษณ์·
Mid-Level
1

Server Action ใน Next.js คืออะไร?

คำตอบ

Server Action คือฟังก์ชัน async ที่ทำงานบนเซิร์ฟเวอร์เท่านั้นและสามารถเรียกใช้โดยตรงจาก component Client หรือ Server ได้ มันจัดการ mutations ข้อมูล (POST, PUT, DELETE) โดยไม่ต้องสร้าง API route อย่างชัดเจน Server Actions ทำให้โค้ดง่ายขึ้นโดยหลีกเลี่ยงการซ้ำกันของ API route + การเรียก fetch ฝั่ง client

2

วิธีประกาศ Server Action ในไฟล์แยกคืออะไร?

คำตอบ

เพื่อสร้าง Server Action ในไฟล์แยก ให้เพิ่ม directive 'use server' ที่ด้านบนของไฟล์และ export ฟังก์ชัน async วิธีนี้แนะนำเพื่อการนำกลับมาใช้ใหม่และการแยกความรับผิดชอบ จากนั้นฟังก์ชันสามารถ import เข้าใน component Client หรือ Server ใดก็ได้

3

ความแตกต่างระหว่าง Server Action และ API route คืออะไร?

คำตอบ

Server Actions สามารถเรียกใช้ได้โดยตรงจาก component โดยไม่ต้องสร้าง REST endpoint อย่างชัดเจน ในขณะที่ API routes ต้องการการเรียก HTTP (fetch) Server Actions ทำให้โค้ดง่ายขึ้นโดยหลีกเลี่ยงการซ้ำกันของ route + การเรียก client เหมาะสำหรับ mutations ง่ายๆ แต่ API routes ยังคงมีประโยชน์สำหรับ public endpoints หรือ webhooks

4

วิธีใช้ Server Action ในฟอร์ม HTML คืออะไร?

5

Server Action รับข้อมูลประเภทใดจากฟอร์ม?

+17 คำถามสัมภาษณ์

หัวข้อสัมภาษณ์ React / Next.js อื่นๆ

พื้นฐาน JavaScript

Junior
25 คำถาม

พื้นฐาน React

Junior
20 คำถาม

React Hooks

Junior
22 คำถาม

วงจรชีวิตของ component

Junior
18 คำถาม

React Router

Junior
20 คำถาม

การจัดการ state ด้วย Context

Junior
18 คำถาม

ฟอร์มและ Controlled Components

Mid-Level
20 คำถาม

การดึงข้อมูลและ API

Mid-Level
20 คำถาม

React Query (TanStack Query)

Mid-Level
20 คำถาม

Styling & CSS-in-JS

Mid-Level
18 คำถาม

พื้นฐาน Next.js

Mid-Level
25 คำถาม

TypeScript กับ React

Mid-Level
20 คำถาม

การดึงข้อมูล Next.js

Mid-Level
24 คำถาม

การกำหนดเส้นทางและการนำทางใน Next.js

Mid-Level
22 คำถาม

API Routes ใน Next.js

Mid-Level
20 คำถาม

Metadata & SEO ใน Next.js

Mid-Level
18 คำถาม

Middleware และ Auth ใน Next.js

Mid-Level
22 คำถาม

การทดสอบ React

Mid-Level
20 คำถาม

Zustand State Management

Mid-Level
18 คำถาม

การเพิ่มประสิทธิภาพ React

Senior
22 คำถาม

Error Boundaries & การจัดการข้อผิดพลาด

Senior
18 คำถาม

Advanced React Patterns

Senior
20 คำถาม

ฟีเจอร์ขั้นสูงของ Next.js

Senior
24 คำถาม

การ Deploy & Production ของ Next.js

Senior
20 คำถาม

Architecture & Design Patterns

Senior
22 คำถาม

React Server Components

Senior
26 คำถาม

การแปลภาษา Next.js

Senior
20 คำถาม

React ความปลอดภัย & แนวปฏิบัติที่ดีที่สุด

Senior
22 คำถาม

เชี่ยวชาญ React / Next.js สำหรับการสัมภาษณ์ครั้งถัดไป

เข้าถึงคำถามทั้งหมด flashcards แบบทดสอบเทคนิค แบบฝึกหัด code review และตัวจำลองสัมภาษณ์

เริ่มใช้ฟรี