react icon indicating copy to clipboard operation
react copied to clipboard

Review with React 18 types in mind

Open eps1lon opened this issue 2 years ago • 13 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.

  • [x] explicit children (https://github.com/typescript-cheatsheets/react/pull/510)
  • [ ] useCallback implicit any
  • [ ] this.context is unknown
  • [ ] removal of deprecated types

eps1lon avatar Apr 11 '22 06:04 eps1lon

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?

LukasKalbertodt avatar Apr 11 '22 08:04 LukasKalbertodt

I created https://github.com/typescript-cheatsheets/react/pull/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.

filiptammergard avatar Apr 13 '22 21:04 filiptammergard

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: https://github.com/typescript-cheatsheets/react/pull/497

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

filiptammergard avatar Apr 13 '22 21:04 filiptammergard

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.

filiptammergard avatar Apr 13 '22 21:04 filiptammergard

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

swyxio avatar Apr 19 '22 22:04 swyxio

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!

stale[bot] avatar Aug 10 '22 03:08 stale[bot]

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!

stale[bot] avatar Oct 14 '22 07:10 stale[bot]

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!

stale[bot] avatar Dec 16 '22 01:12 stale[bot]

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!

stale[bot] avatar Mar 19 '23 19:03 stale[bot]

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!

stale[bot] avatar May 20 '23 13:05 stale[bot]

From what I understand the last remaining pitfalls with React.FC were fixed with https://github.com/DefinitelyTyped/DefinitelyTyped/commit/443451ccc5db3adf1865853e152636f1a9ba5dd5 released in https://unpkg.com/@types/[email protected]/index.d.ts ?

I'm talking about these two:

Minor Pitfalls

These patterns are not supported:
  Conditional rendering
  Array.fill

jonenst avatar Jul 20 '23 14:07 jonenst

@jonenst Fixed in https://github.com/typescript-cheatsheets/react/pull/633!

filiptammergard avatar Aug 03 '23 16:08 filiptammergard

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!

stale[bot] avatar Mar 17 '24 10:03 stale[bot]