본문 바로가기
Frontend2024년 12월 4일1분 읽기

React 19 새 기능 — use(), Actions, 서버 컴포넌트 개선

YS
김영삼
조회 1637

use() 훅

Promise나 Context를 직접 읽을 수 있는 새로운 훅입니다. 조건부 호출도 가능합니다.

function UserProfile({ userPromise }) {
  const user = use(userPromise);
  return <h1>{user.name}</h1>;
}

// Context 읽기
function Theme() {
  const theme = use(ThemeContext);
  return <div style={{ color: theme.primary }}>...</div>;
}

Actions

function UpdateForm() {
  const [state, formAction] = useActionState(updateUser, initialState);
  return <form action={formAction}>...</form>;
}

댓글 0

아직 댓글이 없습니다.
Ctrl+Enter로 등록