Skip to content

Commit ad0fa64

Browse files
authored
Merge pull request #1081 from reactjs/sync-2b2d0f23
Sync with react.dev @ 2b2d0f2
2 parents b4929a0 + 5b643d5 commit ad0fa64

File tree

2 files changed

+38
-9
lines changed

2 files changed

+38
-9
lines changed

src/content/learn/react-compiler.md

+24-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ title: React 컴파일러
1919
</YouWillLearn>
2020

2121
<Note>
22-
React 컴파일러는 커뮤니티로부터 초기 피드백을 받기 위해 오픈소스로 공개된 새로운 실험적 컴파일러입니다. 아직 안정적이지 않으며 프로덕션 환경에서는 완전히 준비되지 않았습니다.
22+
React 컴파일러는 커뮤니티로부터 초기 피드백을 받기 위해 오픈소스로 공개한 새로운 실험적 컴파일러입니다. 아직 안정적이지 않으며 프로덕션 환경에서는 완전히 준비되지 않았습니다.
2323

2424
React 컴파일러는 React 19 RC를 필요로 합니다. React 19로 업그레이드할 수 없는 경우 [워킹 그룹](https://github.com/reactwg/react-compiler/discussions/6)에 설명된 대로 사용자 공간 캐시 함수 구현을 시도해 볼 수 있습니다. 그러나 이 방법은 권장하지 않으며 가능한 한 React 19로 업그레이드하는 것이 좋습니다.
2525
</Note>
@@ -226,6 +226,29 @@ module.exports = function () {
226226

227227
`babel-plugin-react-compiler`는 다른 Babel 플러그인보다 먼저 실행되어야 합니다. 이는 컴파일러가 사운드 분석(sound analysis)을 위해 입력 소스 정보를 필요로 하기 때문입니다.
228228

229+
React Compiler works best with React 19 RC. If you are unable to upgrade, you can install the extra `react-compiler-runtime` package which will allow the compiled code to run on versions prior to 19. However, note that the minimum supported version is 17.
230+
231+
<TerminalBlock>
232+
npm install react-compiler-runtime@experimental
233+
</TerminalBlock>
234+
235+
You should also add the correct `target` to your compiler config, where `target` is the major version of React you are targeting:
236+
237+
```js {3}
238+
// babel.config.js
239+
const ReactCompilerConfig = {
240+
target: '18' // '17' | '18' | '19'
241+
};
242+
243+
module.exports = function () {
244+
return {
245+
plugins: [
246+
['babel-plugin-react-compiler', ReactCompilerConfig],
247+
],
248+
};
249+
};
250+
```
251+
229252
### Vite {/*usage-with-vite*/}
230253

231254
Vite를 사용하고 있다면, `vite-plugin-react`에 플러그인을 추가할 수 있습니다.

src/content/reference/react/useActionState.md

+14-8
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ React Canary 버전에서 `useActionState` 라고 불리는 이 API 는 React DO
2020
`useActionState`는 폼 액션의 결과를 기반으로 state를 업데이트할 수 있도록 제공하는 Hook 입니다.
2121

2222
```js
23-
const [state, formAction] = useActionState(fn, initialState, permalink?);
23+
const [state, formAction, isPending] = useActionState(fn, initialState, permalink?);
2424
```
2525
2626
</Intro>
@@ -35,7 +35,7 @@ const [state, formAction] = useActionState(fn, initialState, permalink?);
3535
3636
{/* TODO T164397693: link to actions documentation once it exists */}
3737
38-
컴포넌트 최상위 레벨에서 `useActionState`를 호출하여 [폼 액션이 실행될 때](/reference/react-dom/components/form) 업데이트되는 컴포넌트 state를 생성합니다. `useActionState` 기존의 폼 작업 함수와 초기 state를 전달하면, 최신 폼 state와 함께 폼에서 사용하는 새로운 액션을 반환합니다. 최신 폼 state 또한 제공된 함수에 전달됩니다.
38+
컴포넌트 최상위 레벨에서 `useActionState`를 호출하여 [폼 액션이 실행될 때](/reference/react-dom/components/form) 업데이트되는 컴포넌트 state를 생성합니다. `useActionState` 기존의 폼 액션 함수와 초기 state를 전달받고, 폼에서 사용할 새로운 액션을 반환합니다. 이와 함께 최신 폼 state와 액션이 여전히 진행(Pending) 중인지 여부도 반환합니다. 최신 폼 State는 제공된 함수에도 전달됩니다.
3939
4040
```js
4141
import { useActionState } from "react";
@@ -71,10 +71,11 @@ Server Action과 함께 사용하는 경우, `useActionState`를 사용하여 hy
7171
7272
#### 반환값 {/*returns*/}
7373
74-
`useActionState`정확히 두 개의 값이 담긴 배열을 반환합니다.
74+
`useActionState`다음 3가지 값들이 포함된 배열을 반환합니다.
7575
7676
1. 현재 state입니다. 첫 번째 렌더링에서는 전달한 `initialState`와 일치합니다. 액션이 실행된 이후에는 액션에서 반환한 값과 일치합니다.
7777
2. `form` 컴포넌트의 `action` prop에 전달하거나 폼 내부 `button` 컴포넌트의 `formAction` prop에 전달할 수 있는 새로운 액션입니다.
78+
3. 대기 중인 전환(Pending Transition)이 있는지 여부를 알려주는 `isPending` 플래그입니다.
7879
7980
#### 주의 사항 {/*caveats*/}
8081
@@ -104,10 +105,11 @@ function MyComponent() {
104105
}
105106
```
106107
107-
`useActionState`정확히 두 개의 항목으로 구성된 배열을 반환합니다.
108+
`useActionState`다음 3가지 항목들이 포함된 배열을 반환합니다.
108109
109-
1. 폼의 <CodeStep step={1}>현재 state</CodeStep>입니다. 처음에는 제공한 <CodeStep step={4}>초기 state</CodeStep>로 설정되며, 폼이 제출된 후에는 전달한 <CodeStep step={3}>액션</CodeStep>의 반환값으로 설정됩니다.
110-
2. `<form>``action` prop에 전달할 <CodeStep step={2}>새로운 action</CodeStep>입니다.
110+
1. 폼의 <CodeStep step={1}>현재 state</CodeStep>입니다. 처음에는 전달한 <CodeStep step={4}>초기 state</CodeStep>로 설정되며, 폼이 제출된 후에는 전달한 <CodeStep step={3}>액션</CodeStep>의 반환값으로 설정됩니다.
111+
2. `<form>``action` prop에 전달할 <CodeStep step={2}>새로운 액션</CodeStep>입니다.
112+
3. 액션이 처리되는 동안 사용할 수 있는 <CodeStep step={1}>대기(Pending) state</CodeStep>입니다.
111113
112114
폼을 제출하면 전달한 <CodeStep step={3}>액션</CodeStep> 함수가 호출됩니다. 액션의 반환값은 폼의 새로운 <CodeStep step={1}>현재 state</CodeStep>가 됩니다.
113115
@@ -133,13 +135,13 @@ import { useActionState, useState } from "react";
133135
import { addToCart } from "./actions.js";
134136

135137
function AddToCartForm({itemID, itemTitle}) {
136-
const [message, formAction] = useActionState(addToCart, null);
138+
const [message, formAction, isPending] = useActionState(addToCart, null);
137139
return (
138140
<form action={formAction}>
139141
<h2>{itemTitle}</h2>
140142
<input type="hidden" name="itemID" value={itemID} />
141143
<button type="submit">Add to Cart</button>
142-
{message}
144+
{isPending ? "Loading..." : message}
143145
</form>
144146
);
145147
}
@@ -162,6 +164,10 @@ export async function addToCart(prevState, queryData) {
162164
if (itemID === "1") {
163165
return "Added to cart";
164166
} else {
167+
// Add a fake delay to make waiting noticeable.
168+
await new Promise(resolve => {
169+
setTimeout(resolve, 2000);
170+
});
165171
return "Couldn't add to cart: the item is sold out.";
166172
}
167173
}

0 commit comments

Comments
 (0)