-
Notifications
You must be signed in to change notification settings - Fork 365
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
dwiley-akamai
merged 5 commits into
linode:develop
from
dwiley-akamai:M3-6708-react-18-hooks
Mar 12, 2024
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
ad4c451
useId() for Linodes Landing components
DevDW 86aac3f
useId() for GroupByTagToggle.tsx and Virt Mode in LinodeConfigDialog.tsx
DevDW 88c34d9
Update Coding Standards doc
DevDW abd65e5
Flesh out explanation in Coding Standards doc
DevDW 3140e6d
Added changeset: Implement new useId() hook in several components
DevDW File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,9 +15,28 @@ If you are using VSCode it is highly recommended to use the ESlint extension. Th | |
|
||
## React | ||
|
||
- 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). | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
|
||
It should be noted that the `useId()` hook is particularly useful for generating unique IDs for accessibility attributes. For this use case, `useId()` is preferred over hardcoding the ID because components may be rendered more than once on a page, but IDs must be unique. | ||
|
||
As an example from `DisplayLinodes.tsx`, early in the file we invoke the hook: `const displayViewDescriptionId = React.useId()` | ||
|
||
And make use of the unique ID by passing it as the value for a component's `aria-describedby` attribute in the `return` value: | ||
|
||
``` | ||
<StyledToggleButton | ||
aria-describedby={displayViewDescriptionId} | ||
aria-label="Toggle display" | ||
disableRipple | ||
isActive={true} | ||
onClick={toggleLinodeView} | ||
size="large" | ||
> | ||
<GridView /> | ||
</StyledToggleButton> | ||
``` | ||
|
||
Per the [docs](https://react.dev/reference/react/useId#usage), the hook should not be used for generating keys in a list. | ||
|
||
## Event Handler Naming Convention | ||
|
||
|
5 changes: 5 additions & 0 deletions
5
packages/manager/.changeset/pr-10261-tech-stories-1709842863706.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@linode/manager": Tech Stories | ||
--- | ||
|
||
Implement new useId() hook in several components ([#10261](https://github.com/linode/manager/pull/10261)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.