From 981f668da50616f5a6f0bfdc877bcb15ec7ead0a Mon Sep 17 00:00:00 2001 From: Daniel Shleifman Date: Thu, 27 May 2021 18:47:39 +0300 Subject: [PATCH] fixed memory leak --- .../components/DialogTorrentDetailsContent/customHooks.jsx | 5 ++--- web/src/components/DialogTorrentDetailsContent/index.jsx | 6 ++++-- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/web/src/components/DialogTorrentDetailsContent/customHooks.jsx b/web/src/components/DialogTorrentDetailsContent/customHooks.jsx index 550ac0a..aaaeead 100644 --- a/web/src/components/DialogTorrentDetailsContent/customHooks.jsx +++ b/web/src/components/DialogTorrentDetailsContent/customHooks.jsx @@ -36,7 +36,7 @@ export const useUpdateCache = hash => { return cache } -export const useCreateCacheMap = (cache, callback) => { +export const useCreateCacheMap = cache => { const [cacheMap, setCacheMap] = useState([]) useEffect(() => { @@ -67,8 +67,7 @@ export const useCreateCacheMap = (cache, callback) => { } setCacheMap(map) - callback && callback() - }, [cache, callback]) + }, [cache]) return cacheMap } diff --git a/web/src/components/DialogTorrentDetailsContent/index.jsx b/web/src/components/DialogTorrentDetailsContent/index.jsx index fa9843e..b303e9f 100644 --- a/web/src/components/DialogTorrentDetailsContent/index.jsx +++ b/web/src/components/DialogTorrentDetailsContent/index.jsx @@ -6,7 +6,7 @@ import { NoImageIcon } from 'icons' import { getPeerString, humanizeSize } from 'utils/Utils' import { viewedHost } from 'utils/Hosts' import { CopyToClipboard } from 'react-copy-to-clipboard' -import { useState } from 'react' +import { useEffect, useState } from 'react' import { useUpdateCache, useCreateCacheMap } from './customHooks' @@ -116,7 +116,9 @@ export default function DialogTorrentDetailsContent({ closeDialog, torrent }) { } = torrent const cache = useUpdateCache(hash) - const cacheMap = useCreateCacheMap(cache, () => setIsLoading(false)) + const cacheMap = useCreateCacheMap(cache) + + useEffect(() => setIsLoading(false), [cacheMap]) const { Capacity, PiecesCount, PiecesLength } = cache