Frontend2024년 12월 4일1분 읽기

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

YS
YoungSam
조회 1628

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>;
}
ReactReact 19JavaScript

댓글 0

아직 댓글이 없습니다.