You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
<summary>(Deprecated)<b><code>React.VoidFunctionComponent</code> 또는 <code>React.VFC</code> 사용하기</b></summary>
190
+
191
+
[@types/react 16.9.48](https://github.com/DefinitelyTyped/DefinitelyTyped/pull/46643)에서, `React.VoidFunctionComponent` 또는 `React.VFC` type은 `children`을 명시적으로 타이핑(typing) 하기 위해 추가되었습니다.
192
+
하지만, `React.VFC`와 `React.VoidFunctionComponent`는 React 18 (https://github.com/DefinitelyTyped/DefinitelyTyped/pull/59882)에서 더이상 사용되지 않게 되었습니다(deprecated). 따라서 이 임시방편은 React 18+ 에서 더이상 권장되지 않습니다.
193
+
194
+
일반적인 함수 컴포넌트나 `React.FC`를 사용해 주세요.
195
+
196
+
```ts
197
+
typeProps= { foo:string };
198
+
199
+
// 지금은 괜찮지만, 미래에는 에러를 발생시킬 것입니다.
200
+
const FunctionComponent:React.FunctionComponent<Props> = ({ foo, children }:Props) => {
201
+
return (
202
+
<div>
203
+
{foo} {children}
204
+
</div>
205
+
); // OK
206
+
};
207
+
208
+
// 지금은 에러를 발생시키고, 미래에는 더이상 사용되지 않을것입니다.(Deprecated)
209
+
const VoidFunctionComponent:React.VoidFunctionComponent<Props> = ({ foo, children }) => {
210
+
return (
211
+
<div>
212
+
{foo}
213
+
{children}
214
+
</div>
215
+
);
216
+
};
217
+
```
218
+
219
+
</details>
220
+
221
+
-_미래에는_, props를 자동으로 `readonly` 라고 표시할 수도 있습니다. 하지만, props 객체가 파라미터 리스트에서 destructure 된다면, 이것은 의미없는 행동 입니다.
222
+
223
+
대부분의 경우에는 어떤 syntax를 사용하던지 큰 차이가 없지만, `React.FunctionComponent`의 보다 명시적인 특성을 선호하는 것이 좋을것입니다.
224
+
225
+
</details>
226
+
227
+
<details>
228
+
<summary><b>주의해야 할 사항</b></summary>
229
+
230
+
다음의 패턴은 지원되지 않습니다. :
231
+
232
+
**조건부 렌더링(conditional rendering)**
233
+
234
+
```tsx
235
+
const MyConditionalComponent = ({ shouldRender=false }) => (shouldRender? <div /> :false); // JS 에서도 이렇게 하지 마십시오.
236
+
const el = <MyConditionalComponent />; // 에러를 throw 합니다.
237
+
```
238
+
239
+
이 패턴이 지원되지 않는 이유는 컴파일러의 한계 때문입니다. 함수 컴포넌트는 JSX expression 또는 `null` 이외의 다른 어떤 것도 반환할 수 없습니다. 반환할 수 없는 것이 반환된다면 해당 타입은 `Element`에 할당될 수 없다는 에러 메세지를 보게될 것입니다. ("{the other type} is not assignable to `Element`.")
0 commit comments