Skip to content

Commit

Permalink
fix(Menu): add setState condition in updateMiniStore method to avoid …
Browse files Browse the repository at this point in the history
…infinite call in componentDidUpdate
  • Loading branch information
grantedFine committed Feb 13, 2020
1 parent f5f933f commit 193bc52
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions src/Menu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,8 @@ class Menu extends React.Component<MenuProps> {
this.updateMiniStore();
}

componentDidUpdate() {
this.updateMiniStore();
componentDidUpdate(prevProps: MenuProps) {
this.updateMiniStore(prevProps);
}

onSelect = (selectInfo: SelectInfo) => {
Expand Down Expand Up @@ -215,16 +215,20 @@ class Menu extends React.Component<MenuProps> {
this.innerMenu = node;
};

updateMiniStore() {
updateMiniStore(prevProps?: MenuProps) {
if ('selectedKeys' in this.props) {
this.store.setState({
selectedKeys: this.props.selectedKeys || [],
});
if (!prevProps || this.props.selectedKeys !== prevProps.selectedKeys) {
this.store.setState({
selectedKeys: this.props.selectedKeys || [],
});
}
}
if ('openKeys' in this.props) {
this.store.setState({
openKeys: this.props.openKeys || [],
});
if ('openKeys' in this.props && this.props.openKeys.length) {
if (!prevProps || this.props.selectedKeys !== prevProps.openKeys) {
this.store.setState({
openKeys: this.props.openKeys || [],
});
}
}
}

Expand Down

0 comments on commit 193bc52

Please sign in to comment.