Skip to content

Commit 300b09e

Browse files
authored
Merge pull request #24 from 02engine/codex/fix-maximum-update-depth-exceeded-error
Fix SoundTab selected index update loop
2 parents 12f1ebf + 0ca74db commit 300b09e

1 file changed

Lines changed: 8 additions & 3 deletions

File tree

src/containers/sound-tab.jsx

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,14 @@ class SoundTab extends React.Component {
7373

7474
// If switching editing targets, reset the sound index
7575
if (prevProps.editingTarget !== editingTarget) {
76-
this.setState({selectedSoundIndex: 0});
77-
} else if (this.state.selectedSoundIndex > target.sounds.length - 1) {
78-
this.setState({selectedSoundIndex: Math.max(target.sounds.length - 1, 0)});
76+
if (this.state.selectedSoundIndex !== 0) {
77+
this.setState({selectedSoundIndex: 0});
78+
}
79+
} else {
80+
const maxSoundIndex = Math.max(target.sounds.length - 1, 0);
81+
if (this.state.selectedSoundIndex > maxSoundIndex) {
82+
this.setState({selectedSoundIndex: maxSoundIndex});
83+
}
7984
}
8085
}
8186

0 commit comments

Comments
 (0)