-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
chore(react): upgrade React typings to use a more explicit children
prop declaration
#6320
chore(react): upgrade React typings to use a more explicit children
prop declaration
#6320
Conversation
I'm sorry PC, but I'm not a big fan of Dan Abramov himself agrees with all of this too: https://stackoverflow.com/a/71809927/88106 |
No worries, tomato / 🍅; happy to change this to explicitly include As a small aside, curious what the drawback is of using a helper type? |
c4d1652
to
9aaa407
Compare
First, to be clear, for sure it's mostly a personal preference. And because of that, if the rest of the team rather use But, some reasons are:
|
9aaa407
to
5b9c0cc
Compare
...
...
... tbh - I also felt this way when implementing, something about the ergonomics of the wrapper was off; so fwiw having an explicit For whatever reason at the time I implemented (months ago now), it seemed easier just to drop in the helper interface 🤷🏻 |
PropsWithChildren
for a more explicit children
prop declarationchildren
prop declaration
5b9c0cc
to
072e8c7
Compare
This is probably for another PR, but we should also try to decide on |
Agreed although I am much more in the 🙃 - I have had this on my radar for a bit. I already have a separate PR cut for it, but since that change is pretty related to this one; wanted to get this one merged first. |
favor explicit declarations over intersection type see: https://github.com/redwoodjs/redwood/pull/6320/files#r970341633
manually edited in GitHub and formater/linter didn't kick in
In general I agree with this sentiment. But We should discuss this with the team before deciding. |
It may be slightly more welcoming to new users to see it written out. FWIW there is a discussion here that edges close to this question: typescript-cheatsheets/react#190. That also took me to the cheatsheet link: https://react-typescript-cheatsheet.netlify.app/docs/basic/getting-started/function_components/ (oh, gotta click the dropdown on "Why is FC discouraged...") @IThinkThatsKirby mentioned trying to be more verbose in the codebase vs less. |
typescript-cheatsheet says "However, the general consensus today is that React.FunctionComponent (or the shorthand React.FC) is discouraged." That was (maybe) true with the old React 17 types, but I really don't agree anymore with the new React 18 types. But that cheatsheet has been cited as one of the reasons we didn't do React.FunctionComponent before. |
I almost made the caveat that I was not trying to point to that link for the discourage mention. They note FC as the shorthand, but throughout the note they use FunctionComponent. |
I shouldn't get so worked up about this, but I've had this exact argument at work. Where someone wants to use FunctionComponent for the explicitness and newbie friendliness, and I prefer FC for the convenience. That same guy also wants us to use |
TLDR:TDLR:TDLR: 🩳✋= 💯 if 📜 🔥 TLDR:TLDR: That's my take, I'll leave the cringe below I spent to much time over explaining and don't want to feel like my effort was wasted. TLDR: My thoughts on this are pretty simple. That which stands the longest gets the most detail. deletes 7 paragraphs of philosophical we stand on giants , age of fire, gates open come on in blah blah blah commie manifesto, phalanx formation, insert lord of the rings Return of the king quote here. Ok so my personal cringe aside. I realize the debate is more of a where is the "good enough" place to draw the line. |
@IThinkThatsKirby Thanks for sharing. I enjoyed reading all of it 🙂 |
React 18 removed implicit children from the
React.FunctionComponent
type.This PR improves our use of typings to make more explicit when a functional component has a children prop, and as a bonus will allow us to more easily allow migrate to React 18 (#4992).
See also: