Skip to content

Commit 3ea5a43

Browse files
committed
Fix shallow comparison of itemsChanged
1 parent 65d98b8 commit 3ea5a43

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

src/ImageGallery.jsx

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -163,9 +163,17 @@ export default class ImageGallery extends React.Component {
163163
},
164164
};
165165

166+
componentDidMount() {
167+
if (this.props.autoPlay) {
168+
this.play();
169+
}
170+
window.addEventListener('keydown', this._handleKeyDown);
171+
this._onScreenChangeEvent();
172+
}
173+
166174
componentDidUpdate(prevProps, prevState) {
167175
const itemsSizeChanged = prevProps.items.length !== this.props.items.length;
168-
const itemsChanged = prevProps.items !== this.props.items;
176+
const itemsChanged = JSON.stringify(prevProps.items) !== JSON.stringify(this.props.items);
169177
const startIndexUpdated = prevProps.startIndex !== this.props.startIndex;
170178
if (itemsSizeChanged) {
171179
this._handleResize();
@@ -188,14 +196,6 @@ export default class ImageGallery extends React.Component {
188196
}
189197
}
190198

191-
componentDidMount() {
192-
if (this.props.autoPlay) {
193-
this.play();
194-
}
195-
window.addEventListener('keydown', this._handleKeyDown);
196-
this._onScreenChangeEvent();
197-
}
198-
199199
componentWillUnmount() {
200200
window.removeEventListener('keydown', this._handleKeyDown);
201201

0 commit comments

Comments
 (0)