IT/React
React.FC 장단점
솔B
2021. 11. 6. 20:50
장점 - children, propTypes, contextTypes, defaultProps, displayName이 기본적으로 있다.
단점 - children이 필요하지 않는 경우에도 들어가 있으므로 타입이 명확하지 않다!
type FC<P = {}> = FunctionComponent<P>;
interface FunctionComponent<P = {}> {
(props: PropsWithChildren<P>, context?: any): ReactElement<any, any> | null;
propTypes?: WeakValidationMap<P> | undefined;
contextTypes?: ValidationMap<any> | undefined;
defaultProps?: Partial<P> | undefined;
displayName?: string | undefined;
}
그래서 React.FC를 사용하지 않고 children은 따로 명시해주는게 좋다.
https://react.vlpt.us/using-typescript/02-ts-react-basic.html