Skip to content

Commit

Permalink
fix(ui): fix state management on unmounted component
Browse files Browse the repository at this point in the history
  • Loading branch information
ncarlier committed Apr 24, 2020
1 parent 4c33601 commit a67abce
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 5 deletions.
1 change: 1 addition & 0 deletions ui/src/articles/components/MarkAsButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export default (props: Props) => {
variables: { id: article.id, status },
update: updateCacheAfterUpdate,
})
// TODO we should not update state if mutation trigger an unmount on this element
if (!floating) setLoading(false)
if (onSuccess) onSuccess(article)
} catch (err) {
Expand Down
7 changes: 2 additions & 5 deletions ui/src/articles/components/NewArticlesAvailable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,8 @@ export default ({ current, category, refresh }: Props) => {

const reload = useCallback(async () => {
setLoading(true)
try {
await refresh()
} finally {
setLoading(false)
}
await refresh()
// No need to reset loading state because this componemt will be unmounted
}, [refresh])

const getNbArticlesToRead = useCallback(
Expand Down

0 comments on commit a67abce

Please sign in to comment.