Skip to content
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

refactor: [M3-6708] – Implement new React 18 hooks #10261

Merged
merged 5 commits into from
Mar 12, 2024

Conversation

dwiley-akamai
Copy link
Contributor

@dwiley-akamai dwiley-akamai commented Mar 5, 2024

Description πŸ“

With our recent upgrade to React 18, we can begin making use of new hooks that were introduced with that version. This PR implements useId() in a few files.

  • useId
    • One potential use case we discussed early on was using this hook for generating unique IDs for React list items, but the docs explicitly state this should not be done. Of the scenarios outlined in the "Usage" section of the docs, the most relevant one for us is generating unique IDs for accessibility attributes.
  • useTransition
    • Our use of React Query and reliance on the loading state it provides makes useTransition mostly superfluous to us.
  • useDeferredValue
    • May have some applicability, but it cannot be used as a 1:1 replacement everywhere we do debouncing. For example, we often debounce to limit API requests.
  • useInsertionEffect
    • Seems it can be a replacement for componentDidMount and componentWillUnmount, so it may have some applicability when converting class components to function components.

Changes πŸ”„

  • Update Coding Standards doc
  • Implement useId() in GroupByTagToggle.tsx, LinodeConfigDialog.tsx, DisplayGroupedLinodes.tsx, DisplayLinodes.tsx, and SortableTableHead.tsx

How to test πŸ§ͺ

Verification steps

With VoiceOver on, ensure there have been no regressions/changes compared to prod for the following:

  1. Linode Config Dialog -- Virt Mode section
  2. Linode landing page -- Summary/List view button, Group by Tag button

Alternatively or in addition to the above, you can verify by looking at the HTML and confirming that the id and aria-describedby attributes on the related elements match up:

Screenshot 2024-03-07 at 3 31 58β€―PM

As an Author I have considered πŸ€”

  • πŸ‘€ Doing a self review
  • ❔ Our contribution guidelines
  • 🀏 Splitting feature into small PRs
  • βž• Adding a changeset
  • πŸ§ͺ Providing/Improving test coverage
  • πŸ” Removing all sensitive information from the code and PR description
  • 🚩 Using a feature flag to protect the release
  • πŸ‘£ Providing comprehensive reproduction steps
  • πŸ“‘ Providing or updating our documentation
  • πŸ•› Scheduling a pair reviewing session
  • πŸ“± Providing mobile support
  • β™Ώ Providing accessibility support

@dwiley-akamai dwiley-akamai self-assigned this Mar 5, 2024
Comment on lines -18 to -20
- When conditionally rendering JSX, use ternaries instead of `&&`.
- Example: `condition ? <Component /> : null` instead of `condition && <Component />`
- This is to avoid hard-to-catch bugs ([read more](https://kentcdodds.com/blog/use-ternaries-rather-than-and-and-in-jsx)).
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We moved away from this convention about a year ago, but this was lingering in our Coding Standards.

@dwiley-akamai dwiley-akamai marked this pull request as ready for review March 7, 2024 20:36
@dwiley-akamai dwiley-akamai requested a review from a team as a code owner March 7, 2024 20:36
@dwiley-akamai dwiley-akamai requested review from hana-akamai and abailly-akamai and removed request for a team March 7, 2024 20:36
- When conditionally rendering JSX, use ternaries instead of `&&`.
- Example: `condition ? <Component /> : null` instead of `condition && <Component />`
- This is to avoid hard-to-catch bugs ([read more](https://kentcdodds.com/blog/use-ternaries-rather-than-and-and-in-jsx)).
[Several new hooks were introduced with the release of React 18](https://react.dev/blog/2022/03/29/react-v18#new-hooks).
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If/when other newly-introduced hooks get used in the code base, perhaps guidelines/explanations around their usage could be included in this section also.

Copy link
Contributor

@abailly-akamai abailly-akamai left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This makes sense, and achieves the intended result - βœ…

thanks for updating the documentation!

@hana-akamai hana-akamai added the Approved Multiple approvals and ready to merge! label Mar 12, 2024
@dwiley-akamai dwiley-akamai merged commit 9917c8e into linode:develop Mar 12, 2024
18 checks passed
@dwiley-akamai dwiley-akamai deleted the M3-6708-react-18-hooks branch March 12, 2024 18:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Approved Multiple approvals and ready to merge!
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants