It will check also the return type of the component, so if you're using some weird conditional return you'll be sure to return always a valid component.
It's a generic, so you can add the types of your props without caring of React's stuff:
There's a lot of discussion on the use of React.FC around the internet for various reasons, I don't think there's a right or wrong answer, but I rather not use React.FC as it breaks defaultProps and it accepts children being passed for every component (and that's not the behaviour you want for every component).
I rather type props the way the article presents or with the PropsWithChildren generic provided by React.
Thank you both of you guys, as you said, we can use ReactFC or PropsWithChildren types. I forgot to annotate the component's output. However, I avoided props de-structuring on purpose just to make the functions more readable. Really cool feedback 🤓
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
In typescript it's way more concise using the React.FC type:
It will check also the return type of the component, so if you're using some weird conditional return you'll be sure to return always a valid component.
It's a generic, so you can add the types of your props without caring of React's stuff:
Destructuring props is also a good way to KISS, and all the types are correctly inferred.
There's a lot of discussion on the use of React.FC around the internet for various reasons, I don't think there's a right or wrong answer, but I rather not use React.FC as it breaks defaultProps and it accepts children being passed for every component (and that's not the behaviour you want for every component).
I rather type props the way the article presents or with the PropsWithChildren generic provided by React.
Just giving another insight to the discussion!
Thank you both of you guys, as you said, we can use ReactFC or PropsWithChildren types. I forgot to annotate the component's output. However, I avoided props de-structuring on purpose just to make the functions more readable. Really cool feedback 🤓