Skip to content

Commit 6d2eae1

Browse files
authored
fix: centralize state and reduce render cycles to derisk component (#5723)
1 parent 69a7202 commit 6d2eae1

File tree

2 files changed

+6
-17
lines changed

2 files changed

+6
-17
lines changed

src/identity/components/GlobalHeader/GlobalHeaderDropdown/index.tsx

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -63,26 +63,15 @@ export interface Props extends StandardFunctionProps {
6363

6464
type State = {
6565
showTypeAheadMenu: boolean
66-
selectedItem?: TypeAheadMenuItem
6766
}
6867

6968
export class GlobalHeaderDropdown extends React.Component<Props, State> {
7069
constructor(props: Props) {
7170
super(props)
7271
this.state = {
7372
showTypeAheadMenu: this.props.onlyRenderSubmenu ?? false,
74-
selectedItem: this.props.typeAheadSelectedOption || null,
7573
}
7674
}
77-
78-
componentDidUpdate() {
79-
if (this.props.typeAheadSelectedOption !== this.state.selectedItem) {
80-
this.setState({
81-
selectedItem: this.props.typeAheadSelectedOption,
82-
})
83-
}
84-
}
85-
8675
private dropdownButton = (
8776
active: boolean,
8877
onClick: (e: MouseEvent<HTMLElement>) => void
@@ -92,8 +81,8 @@ export class GlobalHeaderDropdown extends React.Component<Props, State> {
9281
defaultTestID,
9382
dropdownButtonIcon,
9483
dropdownButtonSize,
84+
typeAheadSelectedOption,
9585
} = this.props
96-
const {selectedItem} = this.state
9786
return (
9887
<Dropdown.Button
9988
active={active}
@@ -103,7 +92,7 @@ export class GlobalHeaderDropdown extends React.Component<Props, State> {
10392
testID={defaultTestID}
10493
trailingIcon={dropdownButtonIcon || IconFont.DoubleCaretVertical}
10594
>
106-
{selectedItem?.name || defaultButtonText}
95+
{typeAheadSelectedOption?.name || defaultButtonText}
10796
</Dropdown.Button>
10897
)
10998
}
@@ -154,17 +143,17 @@ export class GlobalHeaderDropdown extends React.Component<Props, State> {
154143
}
155144

156145
private renderTypeAheadMenu = () => {
157-
const {typeAheadMenuOptions} = this.props
158-
const {selectedItem} = this.state
159146
const {
160147
dropdownMenuStyle,
148+
typeAheadMenuOptions,
149+
typeAheadSelectedOption,
161150
typeAheadEventPrefix,
162151
typeAheadInputPlaceholder,
163152
typeAheadOnSelectOption,
164153
} = this.props
165154
return (
166155
<GlobalHeaderTypeAheadMenu
167-
defaultSelectedItem={selectedItem}
156+
defaultSelectedItem={typeAheadSelectedOption ?? null}
168157
onSelectOption={typeAheadOnSelectOption}
169158
style={dropdownMenuStyle}
170159
testID={this.props.typeAheadTestID}

src/shared/contexts/buckets.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ export const BucketProvider: FC<Props> = ({
102102
)
103103
)
104104
}
105-
}, [buckets, loading])
105+
}, [buckets, dispatch, loading])
106106

107107
// TODO: load bucket creation limits on org change
108108
// expose limits to frontend

0 commit comments

Comments
 (0)