Skip to content

Commit 8233481

Browse files
merging all conflicts
2 parents 5f9486b + 2b2d0f2 commit 8233481

2 files changed

Lines changed: 54 additions & 3 deletions

File tree

src/content/learn/react-compiler.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,13 @@ title: React 컴파일러
1919
</YouWillLearn>
2020

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

2425
React 컴파일러는 React 19 RC를 필요로 합니다. React 19로 업그레이드할 수 없는 경우 [워킹 그룹](https://github.com/reactwg/react-compiler/discussions/6)에 설명된 대로 사용자 공간 캐시 함수 구현을 시도해 볼 수 있습니다. 그러나 이 방법은 권장하지 않으며 가능한 한 React 19로 업그레이드하는 것이 좋습니다.
26+
=======
27+
React Compiler is a new experimental compiler that we've open sourced to get early feedback from the community. It still has rough edges and is not yet fully ready for production.
28+
>>>>>>> 2b2d0f2309f49c82cf5bb88ea62fb2e44661c634
2529
</Note>
2630
2731
React 컴파일러는 빌드 타임 전용 도구로 React 앱을 자동으로 최적화합니다. 순수 JavaScript로 동작하며 [React의 규칙](/reference/rules)을 이해하므로 코드를 다시 작성할 필요가 없습니다.
@@ -226,6 +230,29 @@ module.exports = function () {
226230

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

233+
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.
234+
235+
<TerminalBlock>
236+
npm install react-compiler-runtime@experimental
237+
</TerminalBlock>
238+
239+
You should also add the correct `target` to your compiler config, where `target` is the major version of React you are targeting:
240+
241+
```js {3}
242+
// babel.config.js
243+
const ReactCompilerConfig = {
244+
target: '18' // '17' | '18' | '19'
245+
};
246+
247+
module.exports = function () {
248+
return {
249+
plugins: [
250+
['babel-plugin-react-compiler', ReactCompilerConfig],
251+
],
252+
};
253+
};
254+
```
255+
229256
### Vite {/*usage-with-vite*/}
230257

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

src/content/reference/react/useActionState.md

Lines changed: 27 additions & 3 deletions
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,11 @@ const [state, formAction] = useActionState(fn, initialState, permalink?);
3535
3636
{/* TODO T164397693: link to actions documentation once it exists */}
3737
38+
<<<<<<< HEAD
3839
컴포넌트 최상위 레벨에서 `useActionState`를 호출하여 [폼 액션이 실행될 때](/reference/react-dom/components/form) 업데이트되는 컴포넌트 state를 생성합니다. `useActionState`에 기존의 폼 작업 함수와 초기 state를 전달하면, 최신 폼 state와 함께 폼에서 사용하는 새로운 액션을 반환합니다. 최신 폼 state 또한 제공된 함수에 전달됩니다.
40+
=======
41+
Call `useActionState` at the top level of your component to create component state that is updated [when a form action is invoked](/reference/react-dom/components/form). You pass `useActionState` an existing form action function as well as an initial state, and it returns a new action that you use in your form, along with the latest form state and whether the Action is still pending. The latest form state is also passed to the function that you provided.
42+
>>>>>>> 2b2d0f2309f49c82cf5bb88ea62fb2e44661c634
3943
4044
```js
4145
import { useActionState } from "react";
@@ -71,10 +75,18 @@ Server Action과 함께 사용하는 경우, `useActionState`를 사용하여 hy
7175
7276
#### 반환값 {/*returns*/}
7377
78+
<<<<<<< HEAD
7479
`useActionState`는 정확히 두 개의 값이 담긴 배열을 반환합니다.
7580
7681
1. 현재 state입니다. 첫 번째 렌더링에서는 전달한 `initialState`와 일치합니다. 액션이 실행된 이후에는 액션에서 반환한 값과 일치합니다.
7782
2. `form` 컴포넌트의 `action` prop에 전달하거나 폼 내부 `button` 컴포넌트의 `formAction` prop에 전달할 수 있는 새로운 액션입니다.
83+
=======
84+
`useActionState` returns an array with the following values:
85+
86+
1. The current state. During the first render, it will match the `initialState` you have passed. After the action is invoked, it will match the value returned by the action.
87+
2. A new action that you can pass as the `action` prop to your `form` component or `formAction` prop to any `button` component within the form.
88+
3. The `isPending` flag that tells you whether there is a pending Transition.
89+
>>>>>>> 2b2d0f2309f49c82cf5bb88ea62fb2e44661c634
7890
7991
#### 주의 사항 {/*caveats*/}
8092
@@ -104,10 +116,18 @@ function MyComponent() {
104116
}
105117
```
106118
119+
<<<<<<< HEAD
107120
`useActionState`는 정확히 두 개의 항목으로 구성된 배열을 반환합니다.
108121
109122
1. 폼의 <CodeStep step={1}>현재 state</CodeStep>입니다. 처음에는 제공한 <CodeStep step={4}>초기 state</CodeStep>로 설정되며, 폼이 제출된 후에는 전달한 <CodeStep step={3}>액션</CodeStep>의 반환값으로 설정됩니다.
110123
2. `<form>``action` prop에 전달할 <CodeStep step={2}>새로운 action</CodeStep>입니다.
124+
=======
125+
`useActionState` returns an array with the following items:
126+
127+
1. The <CodeStep step={1}>current state</CodeStep> of the form, which is initially set to the <CodeStep step={4}>initial state</CodeStep> you provided, and after the form is submitted is set to the return value of the <CodeStep step={3}>action</CodeStep> you provided.
128+
2. A <CodeStep step={2}>new action</CodeStep> that you pass to `<form>` as its `action` prop.
129+
3. A <CodeStep step={1}>pending state</CodeStep> that you can utilise whilst your action is processing.
130+
>>>>>>> 2b2d0f2309f49c82cf5bb88ea62fb2e44661c634
111131
112132
폼을 제출하면 전달한 <CodeStep step={3}>액션</CodeStep> 함수가 호출됩니다. 액션의 반환값은 폼의 새로운 <CodeStep step={1}>현재 state</CodeStep>가 됩니다.
113133
@@ -133,13 +153,13 @@ import { useActionState, useState } from "react";
133153
import { addToCart } from "./actions.js";
134154

135155
function AddToCartForm({itemID, itemTitle}) {
136-
const [message, formAction] = useActionState(addToCart, null);
156+
const [message, formAction, isPending] = useActionState(addToCart, null);
137157
return (
138158
<form action={formAction}>
139159
<h2>{itemTitle}</h2>
140160
<input type="hidden" name="itemID" value={itemID} />
141161
<button type="submit">Add to Cart</button>
142-
{message}
162+
{isPending ? "Loading..." : message}
143163
</form>
144164
);
145165
}
@@ -162,6 +182,10 @@ export async function addToCart(prevState, queryData) {
162182
if (itemID === "1") {
163183
return "Added to cart";
164184
} else {
185+
// Add a fake delay to make waiting noticeable.
186+
await new Promise(resolve => {
187+
setTimeout(resolve, 2000);
188+
});
165189
return "Couldn't add to cart: the item is sold out.";
166190
}
167191
}

0 commit comments

Comments
 (0)