import React from 'react';
type GreetingsProps = {
name: string;
};
const Greetings: React.FC<GreetingsProps> = ({ name }) => (
<div>Hello, {name}</div>
);
export default Greetings;
export const Greeting: React.FC<GreetingProps> = ({ name }) => {
return <h1>Hello {name}</h1>
}
const App = () => (
<>
<Greeting name="Stefan">
<span>{"I can set this element but it doesn't do anything"}</span> // children 전달
</Greeting>
</>
)
type GreetingsProps = {
name: string;
mark: string;
};
const Greetings: React.FC<GreetingsProps> = ({ name, mark }) => (
<div>
Hello, {name} {mark}
</div>
);
Greetings.defaultProps = {
mark: '!' // 유효하지 않음.
};
export default Greetings;
const C1: React.FC<CProps> = (props) => { }
const C2 = (props: CProps) => {};
React.FC를 쓰는 것이 꼭 나쁜 것 만은 아니라고 생각은 합니다. 향후 개선이 될 수도 있고 여전히 이 부분을 사용하는게 좋은 경우도 있을 것이다.
하지만 필자의 생각은 React.FC를 사용하지 않고 props 타입을 직접 지정해 주는 것이 더욱 타입스크립트 같고, 다양한 경우에서 안전하다고 한다.