Skip to content

Commit d4abd68

Browse files
okaiokai
authored andcommitted
docs(blog): SEO 기술 팁 포스트 추가 - React Compiler 자동 메모이제이션 (3개 언어)
1 parent 95d5a52 commit d4abd68

3 files changed

Lines changed: 238 additions & 0 deletions
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
---
2+
layout: post
3+
title: "React Compiler: Drop useMemo and useCallback, Let the Compiler Handle It"
4+
date: 2026-03-23 09:00:00 +0900
5+
categories: [Development, Tips]
6+
tags: [React, React Compiler, useMemo, useCallback, Performance]
7+
author: "Kevin Park"
8+
lang: en
9+
excerpt: "React Compiler automatically memoizes your components at build time, eliminating the need for manual useMemo and useCallback in most cases."
10+
---
11+
12+
## Problem
13+
14+
Manual memoization with `useMemo` and `useCallback` has long been a pain point in React development. Forget one, and you get unnecessary re-renders. Add them everywhere, and you're stuck managing dependency arrays.
15+
16+
```jsx
17+
// This was everywhere in every component
18+
const filteredList = useMemo(() => {
19+
return items.filter(item => item.active);
20+
}, [items]);
21+
22+
const handleClick = useCallback((id) => {
23+
setSelected(id);
24+
}, []);
25+
```
26+
27+
Deciding what to memoize was a constant cognitive overhead.
28+
29+
## Solution
30+
31+
React Compiler v1.0 handles memoization automatically at build time.
32+
33+
For Next.js, it's a one-liner:
34+
35+
```js
36+
// next.config.js
37+
const nextConfig = {
38+
reactCompiler: true,
39+
};
40+
41+
module.exports = nextConfig;
42+
```
43+
44+
For existing projects, use the Babel plugin:
45+
46+
```bash
47+
npm install -D babel-plugin-react-compiler
48+
```
49+
50+
```js
51+
// babel.config.js
52+
module.exports = {
53+
plugins: [
54+
['babel-plugin-react-compiler'],
55+
],
56+
};
57+
```
58+
59+
Now you can write plain code and let the compiler optimize:
60+
61+
```jsx
62+
// The compiler inserts memoization automatically
63+
const filteredList = items.filter(item => item.active);
64+
65+
const handleClick = (id) => {
66+
setSelected(id);
67+
};
68+
```
69+
70+
No manual `useMemo` or `useCallback` needed. The compiler analyzes your components and inserts memoization where it matters.
71+
72+
## Key Points
73+
74+
- React Compiler analyzes components at build time and applies automatic memoization
75+
- Eliminates the need for `useMemo`, `useCallback`, and `React.memo` in 95%+ of cases
76+
- Next.js: just set `reactCompiler: true` in your config
77+
- Existing manual memoization still works — no conflicts
78+
- Your code must follow React's rules (pure functions, immutability) for the compiler to optimize effectively
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
---
2+
layout: post
3+
title: "React Compilerを導入したらuseMemoとuseCallbackが不要になった話"
4+
date: 2026-03-23 09:00:00 +0900
5+
categories: [Development, Tips]
6+
tags: [React, React Compiler, useMemo, useCallback, パフォーマンス最適化]
7+
author: "Kevin Park"
8+
lang: ja
9+
excerpt: "React Compilerがビルド時に自動でメモ化を行うため、useMemoやuseCallbackを手動で書く必要がほぼなくなりました。"
10+
---
11+
12+
## 問題
13+
14+
Reactでパフォーマンスを最適化するために、`useMemo``useCallback`を至る所に書くのが日常でした。
15+
書き忘れると不要な再レンダリングが発生し、書いたら書いたで依存配列の管理が大変です。
16+
17+
```jsx
18+
// すべてのコンポーネントにこのようなコードがありました
19+
const filteredList = useMemo(() => {
20+
return items.filter(item => item.active);
21+
}, [items]);
22+
23+
const handleClick = useCallback((id) => {
24+
setSelected(id);
25+
}, []);
26+
```
27+
28+
「これはメモ化すべきか?」と毎回悩むのも負担でした。
29+
30+
## 解決方法
31+
32+
React Compiler v1.0のリリースにより、この悩みが解消されました。
33+
ビルド時にコンパイラが自動的にメモ化を挿入してくれます。
34+
35+
Next.jsでの設定は非常に簡単です。
36+
37+
```js
38+
// next.config.js
39+
const nextConfig = {
40+
reactCompiler: true,
41+
};
42+
43+
module.exports = nextConfig;
44+
```
45+
46+
既存プロジェクトにはBabelプラグインで導入できます。
47+
48+
```bash
49+
npm install -D babel-plugin-react-compiler
50+
```
51+
52+
```js
53+
// babel.config.js
54+
module.exports = {
55+
plugins: [
56+
['babel-plugin-react-compiler'],
57+
],
58+
};
59+
```
60+
61+
これで、先ほどのコードをシンプルに書き換えられます。
62+
63+
```jsx
64+
// コンパイラが自動的に最適化してくれます
65+
const filteredList = items.filter(item => item.active);
66+
67+
const handleClick = (id) => {
68+
setSelected(id);
69+
};
70+
```
71+
72+
`useMemo``useCallback`を削除しても、コンパイラがビルド時に自動でメモ化を適用します。
73+
74+
## ポイント
75+
76+
- React Compilerはビルド時にコンポーネントを解析し、自動的にメモ化を適用します
77+
- `useMemo``useCallback``React.memo`を手動で書く必要が95%以上なくなります
78+
- Next.jsでは`reactCompiler: true`の1行で設定完了です
79+
- 既存のuseMemo/useCallbackコードもそのまま動作します(競合なし)
80+
- コンパイラが最適化できるよう、Reactのルール(純粋関数、不変性)を守ることが重要です
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
---
2+
layout: post
3+
title: "React Compiler 적용했더니 useMemo, useCallback 다 지워도 되더라"
4+
date: 2026-03-23 09:00:00 +0900
5+
categories: [Development, Tips]
6+
tags: [React, React Compiler, useMemo, useCallback, 성능최적화]
7+
author: "Kevin Park"
8+
lang: ko
9+
excerpt: "React Compiler가 자동으로 메모이제이션을 해주면서 useMemo, useCallback을 직접 쓸 일이 거의 없어졌다. 설정법과 실무 적용기."
10+
---
11+
12+
## 문제
13+
14+
React에서 성능 최적화한다고 useMemo, useCallback을 덕지덕지 붙이는 게 일상이었다.
15+
근데 솔직히 이거 빼먹으면 리렌더링 폭발하고, 넣으면 넣는 대로 의존성 배열 관리가 지옥이었다.
16+
17+
```jsx
18+
// 이런 코드가 컴포넌트마다 있었다
19+
const filteredList = useMemo(() => {
20+
return items.filter(item => item.active);
21+
}, [items]);
22+
23+
const handleClick = useCallback((id) => {
24+
setSelected(id);
25+
}, []);
26+
```
27+
28+
매번 "이거 메모이제이션 해야 하나?" 고민하는 것도 피곤했다.
29+
30+
## 해결
31+
32+
React Compiler v1.0이 나오면서 이 고민이 사라졌다.
33+
빌드 타임에 컴파일러가 알아서 메모이제이션을 넣어준다.
34+
35+
Next.js에서 설정하는 법은 간단하다.
36+
37+
```js
38+
// next.config.js
39+
const nextConfig = {
40+
reactCompiler: true,
41+
};
42+
43+
module.exports = nextConfig;
44+
```
45+
46+
기존 프로젝트에 Babel 플러그인으로 넣을 수도 있다.
47+
48+
```bash
49+
npm install -D babel-plugin-react-compiler
50+
```
51+
52+
```js
53+
// babel.config.js
54+
module.exports = {
55+
plugins: [
56+
['babel-plugin-react-compiler'],
57+
],
58+
};
59+
```
60+
61+
이제 아까 그 코드를 이렇게 바꿔도 된다.
62+
63+
```jsx
64+
// 컴파일러가 알아서 최적화해준다
65+
const filteredList = items.filter(item => item.active);
66+
67+
const handleClick = (id) => {
68+
setSelected(id);
69+
};
70+
```
71+
72+
useMemo, useCallback을 지워도 컴파일러가 빌드할 때 자동으로 메모이제이션을 삽입한다.
73+
74+
## 핵심 포인트
75+
76+
- React Compiler는 빌드 타임에 컴포넌트를 분석해서 자동으로 메모이제이션을 적용한다
77+
- useMemo, useCallback, React.memo를 직접 쓸 필요가 95% 이상 사라진다
78+
- Next.js는 `reactCompiler: true` 한 줄이면 끝이다
79+
- 기존에 useMemo/useCallback 쓰던 코드도 그대로 동작한다 (충돌 없음)
80+
- 단, 컴파일러가 최적화할 수 있으려면 React의 규칙(순수 함수, 불변성)을 잘 지켜야 한다

0 commit comments

Comments
 (0)