frontend: Dialog: move useCallback before early return to fix rules-of-hooks#5208
frontend: Dialog: move useCallback before early return to fix rules-of-hooks#5208jedbillyb wants to merge 3 commits intokubernetes-sigs:mainfrom
Conversation
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: jedbillyb The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
|
/lgtm |
There was a problem hiding this comment.
Pull request overview
This PR fixes an ESLint react-hooks/rules-of-hooks violation in DialogTitle by ensuring useCallback is always invoked before any early returns, and updates the hook dependencies to match referenced props.
Changes:
- Move the
focusedRefReact.useCallbackabove the guard-clause early return inDialogTitle. - Add
focusTitleto theuseCallbackdependency array (previously missing).
| (node: HTMLElement) => { | ||
| if (node !== null) { | ||
| if (focusTitle) { | ||
| node.setAttribute('tabindex', '-1'); | ||
| node.focus(); | ||
| } |
illume
left a comment
There was a problem hiding this comment.
Sorry, another PR was merged and there's now a git conflict.
Are you able to fix the git conflict?
Signed-off-by: Jed Blenkhorn <[email protected]>
|
New changes are detected. LGTM label has been removed. |
|
@illume fixed! |
Fixes #5186
Moves
React.useCallbackinDialogTitleto before the early returnguard clause, satisfying rules-of-hooks. Also adds
focusTitleto thedependency array which was previously missing.
Steps to test:
npx eslint src/components/common/Dialog.tsx- no rules-of-hooks warnings