typescript-cheatsheets / react

Cheatsheets for experienced React developers getting started with TypeScript

Home Page:https://react-typescript-cheatsheet.netlify.app

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Review with React 18 types in mind

eps1lon opened this issue · comments

We had some type-related breaking changes with React 18 that were supposed to fix long standing issues. If we describe these issues here, reference React 18 types that fix those issues.

  • explicit children (#510)
  • useCallback implicit any
  • this.context is unknown
  • removal of deprecated types

In particular, the guide also mentions that React.FC is discouraged. The main reason against it seems to be the implicit children. But this has changed with 18.0.0, so I wonder if FC is still discouraged. The remaining reasons against it seem rather minor?

I created #496 before I saw this. Let me know if you want to handle it in another way or feel free to just close the PR.

The other place that came to mind was the section "Small React.ReactNode edge case" here: https://react-typescript-cheatsheet.netlify.app/docs/basic/getting-started/basic_type_example/#useful-react-prop-type-examples. Created a PR for that as well: #497

But I'm not sure how you would like to convey this, so just let me know if you have other ideas.

In particular, the guide also mentions that React.FC is discouraged. The main reason against it seems to be the implicit children. But this has changed with 18.0.0, so I wonder if FC is still discouraged. The remaining reasons against it seem rather minor?

The main reason behind React.FC being discouraged might be gone, but there are still some smaller problems remaining and no real benefits with using it. Even though React.FC might not need to be discouraged as much, I still wouldn't encourage using it.

hey @filiptammergard really appreciate the comments! I just invited you to help maintain this repo :)

i've personally never used React.FC so never engaged in that debate but let me know if the consensus shifts :) all i care about on that topic is just to give a concise summary of the tradeoffs if you choose ot use it

commented

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions!

commented

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions!

commented

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions!

commented

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions!

commented

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions!

From what I understand the last remaining pitfalls with React.FC were fixed with DefinitelyTyped/DefinitelyTyped@443451c released in https://unpkg.com/@types/react@18.2.8/index.d.ts ?

I'm talking about these two:

Minor Pitfalls

These patterns are not supported:
  Conditional rendering
  Array.fill

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions!