Framework/React

[React] React.FC ์˜ ์˜๋ฏธ์™€ ์‚ฌ์šฉํ•˜์ง€ ์•Š๋Š” ์ด์œ 

yuri lee 2022. 10. 2. 14:29
๋ฐ˜์‘ํ˜•

Intro

React.FC์˜ ์˜๋ฏธ์™€ ์‚ฌ์šฉํ•˜์ง€ ์•Š๋Š” ์ด์œ ์— ๋Œ€ํ•ด ์•Œ์•„๋ณด๋„๋ก ํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค. 

type Props = {

};

const TestComponent: React.FC<Props> = () => {
    return (
        <div>
            TestComponent  
        </div>
    );
};

export default TestComponent;

ํ˜„์žฌ React typescript๋ฅผ ์‚ฌ์šฉํ•˜๊ณ  ์žˆ๋Š” ํ”„๋กœ์ ํŠธ์—์„œ ์ปดํฌ๋„ŒํŠธ๋ฅผ ์ž‘์„ฑํ•  ๋•Œ ๋‹ค์Œ๊ณผ ๊ฐ™์€ ๋ฐฉ๋ฒ•์„ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค. 

 

 

FC๋ฅผ ์‚ฌ์šฉํ•˜์ง€ ๋ง์•„์•ผ ํ•˜๋Š” ์ด์œ  

ํ•˜์ง€๋งŒ ๐Ÿคจ React typescript๋Š” ๊ทธ๋‹ค์ง€ ์ข‹์€ ๋ฐฉ๋ฒ•์ด๋ผ๊ณ  ํ•ฉ๋‹ˆ๋‹ค. ๊ทธ์ค‘์—์„œ ๊ฐ€์žฅ ํฐ ์ด์œ ๋Š” props์ด ์•”์‹œ์ ์œผ๋กœ ๋“ค์–ด๊ฐ€ ์žˆ๊ธฐ ๋•Œ๋ฌธ์ž…๋‹ˆ๋‹ค. 

 

  • children์„ ์•”์‹œ์ ์œผ๋กœ ๊ฐ€์ง€๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค.
  • ์ œ๋„ค๋ฆญ์„ ์ง€์›ํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค. 
  • ๋„ค์ž„ ์ŠคํŽ˜์ด์Šค ํŒจํ„ด์„ ์ด์šฉํ•  ๋•Œ ๋” ๋ถˆํŽธํ•ฉ๋‹ˆ๋‹ค. 
  • FC๋ฅผ ์ด์šฉํ•˜๋ฉด ์ฝ”๋“œ๊ฐ€ ๋” ๊ธธ์–ด์ง‘๋‹ˆ๋‹ค. 

 

๊ฒฐ๊ตญ React 18 version + ์—์„œ ์‚ฌ๋ผ์กŒ๋‹ค๊ณ  ํ•ฉ๋‹ˆ๋‹ค. ํ˜น์‹œ React.FC๋ฅผ ์‚ฌ์šฉํ•˜๊ณ  ๊ณ„์‹ ๋‹ค๋ฉด ์œ ์˜ํ•ด์ฃผ์„ธ์š” ๐Ÿ˜‰ !!


https://emewjin.github.io/why-not-fc/

https://velog.io/@ww8007/Typescript-React.FC

๋ฐ˜์‘ํ˜•