Skip to content

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

Merged
dwiley-akamai merged 5 commits into
linode:developfrom
dwiley-akamai:M3-6708-react-18-hooks
Mar 12, 2024
Merged

dwiley-akamai merged 5 commits into
linode:developfrom
dwiley-akamai:M3-6708-react-18-hooks

Conversation

@dwiley-akamai

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

Copy link
Copy Markdown
Contributor

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
Copy Markdown
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 abailly-akamai and hana-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
Copy Markdown
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.

@abailly-akamai abailly-akamai left a comment

Copy link
Copy Markdown
Contributor

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
@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