Skip to content

Commit b1322a3

Browse files
committed
refactor: optimize ErrorBar component by replacing useEffect with useMemo for improved performance
1 parent 7218d58 commit b1322a3

File tree

1 file changed

+15
-27
lines changed

1 file changed

+15
-27
lines changed

src/Shared/Components/Error/ErrorBar.tsx

Lines changed: 15 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* limitations under the License.
1515
*/
1616

17-
import { useEffect, useState } from 'react'
17+
import { useMemo } from 'react'
1818
import { NavLink } from 'react-router-dom'
1919

2020
import { ReactComponent as ErrorInfo } from '../../../Assets/Icon/ic-errorInfo.svg'
@@ -24,33 +24,21 @@ import { AppDetailsErrorType, ErrorBarType } from './types'
2424
import { renderErrorHeaderMessage } from './utils'
2525

2626
const ErrorBar = ({ appDetails }: ErrorBarType) => {
27-
const [isImagePullBackOff, setIsImagePullBackOff] = useState(false)
28-
29-
useEffect(() => {
30-
if (appDetails.appType === AppType.DEVTRON_APP && appDetails.resourceTree?.nodes?.length) {
31-
for (let index = 0; index < appDetails.resourceTree.nodes.length; index++) {
32-
const node = appDetails.resourceTree.nodes[index]
33-
let _isImagePullBackOff = false
34-
if (node.info?.length) {
35-
for (let idx = 0; idx < node.info.length; idx++) {
36-
const info = node.info[idx]
37-
if (
38-
info.value &&
39-
(info.value.toLowerCase() === AppDetailsErrorType.ERRIMAGEPULL ||
40-
info.value.toLowerCase() === AppDetailsErrorType.IMAGEPULLBACKOFF)
41-
) {
42-
_isImagePullBackOff = true
43-
break
44-
}
45-
}
46-
47-
if (_isImagePullBackOff) {
48-
setIsImagePullBackOff(true)
49-
break
50-
}
51-
}
52-
}
27+
const isImagePullBackOff = useMemo(() => {
28+
if (appDetails?.appType === AppType.DEVTRON_APP && appDetails?.resourceTree?.nodes?.length) {
29+
appDetails.resourceTree.nodes.some(
30+
(node) =>
31+
!!node.info?.some((info) => {
32+
const infoValueLowerCase = info?.value?.toLowerCase()
33+
return (
34+
infoValueLowerCase === AppDetailsErrorType.ERRIMAGEPULL ||
35+
infoValueLowerCase === AppDetailsErrorType.IMAGEPULLBACKOFF
36+
)
37+
}),
38+
)
5339
}
40+
41+
return false
5442
}, [appDetails])
5543

5644
if (

0 commit comments

Comments
 (0)