Fix bug when switching collection or sketch lists (fixes #1401) (#1416)

* Update sketch/collection list when URL changes (fixes #1401)

Using the username as the key prop causes the List component to remount
when the username changes. This means we don't have to bother resetting
everything when the user changes.

* Update deprecated SketchList lifecycle methods

From componentWillReceiveProps to componentDidUpdate
This commit is contained in:
Andrew Nicolaou 2020-05-03 22:51:01 +02:00 committed by GitHub
parent 138bfd6065
commit 4f1b9e3700
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 5 deletions

View file

@ -333,8 +333,9 @@ class SketchList extends React.Component {
};
}
componentWillReceiveProps(nextProps) {
if (this.props.sketches !== nextProps.sketches && Array.isArray(nextProps.sketches)) {
componentDidUpdate(prevProps) {
if (this.props.sketches !== prevProps.sketches && Array.isArray(this.props.sketches)) {
// eslint-disable-next-line react/no-did-update-set-state
this.setState({
isInitialDataLoad: false,
});

View file

@ -98,12 +98,12 @@ class DashboardView extends React.Component {
renderContent(tabKey, username) {
switch (tabKey) {
case TabKey.assets:
return <AssetList username={username} />;
return <AssetList key={username} username={username} />;
case TabKey.collections:
return <CollectionList username={username} />;
return <CollectionList key={username} username={username} />;
case TabKey.sketches:
default:
return <SketchList username={username} />;
return <SketchList key={username} username={username} />;
}
}