Загрузка видео...

Не удалось загрузить видео

На главную

🔥 TypeScript + React Tip 🔥 I've stopped using React.FC to type my Function Components. Here's why:

54,355 просмотров • 3 лет назад •via X (Twitter)

Комментарии: 21

Фото профиля Pedro Figueiredo
Pedro Figueiredo3 лет назад

I was using `React.VFC<Props>` which was basically `React.FC` without the children prop, but since React v18, it doesn't have the children anymore, so, I still think that `React.FC` is a good alternative to type your components in a simple manner. 👍

Фото профиля Joe Previte
Joe Previte3 лет назад

might have to redo the video then 🤣 does the other downside still apply related to generic props?

Фото профиля Pedro Figueiredo
Pedro Figueiredo3 лет назад

Yap, that's a nice one, other than that, I'd say there is another super minor and perhaps opinionated downside for `React.FC/VFC`, which is, they also allow the old ways of defining prop types, meaning: - propTypes - defaultProps And I certainly don't want people using those 😅

Фото профиля Joe Previte
Joe Previte3 лет назад

Lol ahh okay. Well good to know then it still isn't the best way to type components (I also wouldn't want people to use propTypes or defaultProps)

Фото профиля ⚡️Federico (rawnly)
⚡️Federico (rawnly)3 лет назад

Children has been removed from FC since react 18 🥲

Фото профиля Joe Previte
Joe Previte3 лет назад

😅😅😅😅

Фото профиля Kishore Andra (KcH)
Kishore Andra (KcH)3 лет назад

@tscoursedotcom This one is a cool video, Joe is killing with expressions 😍 ....

Фото профиля Joe Previte
Joe Previte3 лет назад

@tscoursedotcom haha thanks Kishore! Glad you liked it 🙏

Фото профиля Kishore Andra (KcH)
Kishore Andra (KcH)3 лет назад

@tscoursedotcom absolutely Joe 💯, if it was an YT video the jump from chair reaction would be the ultimate thumbnail 😉

Фото профиля Jake Moreland
Jake Moreland3 лет назад

removed, i believe you can then utilise PropsWithChildren if you wish to then include the broad acceptance of children whilst still using FC

Фото профиля Joe Previte
Joe Previte3 лет назад

moving this to top of replies 👇 may have to make a follow up video lol

Фото профиля Ross McIntyre
Ross McIntyre3 лет назад

children was removed from React.FC in React 18, so that's no longer an issue.

Фото профиля Sujal Shah ✦
Sujal Shah ✦3 лет назад

Thanks for this wonderful explaination!

Фото профиля Joe Previte
Joe Previte3 лет назад

Glad you enjoyed it :D

Фото профиля Khairallah AL-Awady
Khairallah AL-Awady3 лет назад

Great tip, Joe!

Фото профиля Talha Altınel
Talha Altınel3 лет назад

mega cursed

Фото профиля Peter Piekarczyk (🥧🚗🐥)
Peter Piekarczyk (🥧🚗🐥)3 лет назад

Wow I've been doing this for months out of my lack of desire to look into how to do it correctly 😂

Фото профиля Alejandro
Alejandro3 лет назад

There are also some helpful utility types like Omit, Exclude, Pick

Фото профиля Incalapabler
Incalapabler3 лет назад

I really hate having too many exceptions. How are beginners going to learn when there’s deprecated code everywhere?

Фото профиля Joe Previte
Joe Previte3 лет назад

@veryfastsimba apparently it was removed in React 18 so this video may be outdated 🤣

Фото профиля Benny Neugebauer
Benny Neugebauer3 лет назад

Thanks for this info! Now I have to update my own React cheat sheet: 😅

Похожие видео