Frontend2024년 5월 6일1분 읽기

Next.js 14 App Router — Server Actions 실전 활용

YS
YoungSam
조회 2016

Server Actions란

Server Actions는 서버에서 실행되는 비동기 함수로, 클라이언트에서 직접 호출할 수 있습니다. API 라우트 없이 폼 제출, 데이터 변경이 가능합니다.

"use server"

export async function createPost(formData: FormData) {
  const title = formData.get("title") as string;
  await db.post.create({ data: { title } });
  revalidatePath("/posts");
}

useFormStatus

로딩 상태를 자동으로 추적할 수 있습니다.

Next.jsReactServer Actions

댓글 0

아직 댓글이 없습니다.