728x90
React 19의 핵심 변화
React 19는 Actions, use() hook, forwardRef 제거로 개발자 경험을 크게 향상시켰습니다.
1. Actions
function UpdateProfile() {
const [error, submitAction, isPending] = useActionState(
async (prevState, formData) => {
const error = await updateProfile(formData);
if (error) return error;
redirect('/profile');
return null;
}, null
);
return (
<form action={submitAction}>
<button disabled={isPending}>업데이트</button>
{error && <p>{error}</p>}
</form>
);
}
2. use() Hook
import { use } from 'react';
function Comments({ commentsPromise }) {
const comments = use(commentsPromise);
return comments.map(c => <Comment key={c.id} comment={c} />);
}
function ThemeButton({ show }) {
if (!show) return null;
const theme = use(ThemeContext); // 조건부 사용 가능!
return <button style={{ color: theme.primary }}>버튼</button>;
}
3. useOptimistic
function LikeButton({ post }) {
const [optimisticLikes, addOptimisticLike] = useOptimistic(
post.likes, (current) => current + 1
);
async function handleLike() {
addOptimisticLike();
await likePost(post.id);
}
return <button onClick={handleLike}>좋아요 {optimisticLikes}</button>;
}
4. ref를 prop으로 직접 전달 (forwardRef 제거)
function MyInput({ placeholder, ref }) {
return <input placeholder={placeholder} ref={ref} />;
}
<MyInput ref={inputRef} placeholder="입력하세요" />
마이그레이션 포인트
- ReactDOM.render() 완전 제거 → createRoot() 필수
- forwardRef → 일반 ref prop으로 점진적 교체
- useEffect 클린업 타이밍 변경 확인
React 19의 Actions와 useOptimistic은 실제 프로덕션에서 즉시 활용 가능한 강력한 기능입니다.
300x250
'IT & 개발' 카테고리의 다른 글
| Cursor vs GitHub Copilot vs Windsurf - 2026년 AI 코딩 도구 완전 비교 (0) | 2026.03.12 |
|---|---|
| Kubernetes 비용 최적화 완전 가이드 - 클라우드 비용 30% 줄이는 실전 전략 (0) | 2026.03.12 |
| PostgreSQL 성능 최적화 10가지 - DBA 없이도 쿼리 속도 10배 올리기 (0) | 2026.03.12 |
| 소버린 AI(Sovereign AI)란 무엇인가 - 국가 주도 AI의 부상과 개발자가 준비할 것 (0) | 2026.03.12 |
| AI 에이전트 개발 실전 가이드 - LangGraph로 멀티에이전트 시스템 구축하기 (0) | 2026.03.12 |
댓글