Skip to content

Commit

Permalink
Fix useEffect array depencies for remaining pages
Browse files Browse the repository at this point in the history
  • Loading branch information
johnnadeluy committed Feb 28, 2024
1 parent 418edee commit 1207f8d
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 14 deletions.
9 changes: 0 additions & 9 deletions src/components/Table/Table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -93,15 +93,6 @@ const Table = ({ title, dropdownAriaLabel, dropdownFilterItems, columns, data }:

const isOnMobile = useMediaQuery({ query: 'screen and (max-width: 767px)' }) // $mobile variable from ssb-component-library

/* TODO:
* Fix bug; reinitializes 'data' state(?) a few seconds after Tab onClick.
So once after Tab onClick, and twice a few seconds later
Order after Tab onClick: 1. Sets state to current tab table data. 2. Then to previous tab table data. 3. Then back to current tab table data.
* Notes:
- data is a stored in a state that is set by useEffect and an API call on a higher hierarchical level (e.g. TeamOverview)
- No indication of states reinitializing during the view jittering in React Component Developer tools
*/
useEffect(() => {
if (searchFilterKeyword !== '' && data.length) {
const filterTableData = data.filter((row) =>
Expand Down
5 changes: 3 additions & 2 deletions src/pages/TeamDetail/TeamDetail.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable react-hooks/exhaustive-deps */
import styles from './teamDetail.module.scss'

import { useCallback, useContext, useEffect, useState } from 'react'
Expand Down Expand Up @@ -53,7 +54,7 @@ const TeamDetail = () => {
.catch((error) => {
setError({ error: { message: error.message, code: '500' } })
})
}, [teamId])
}, [])

useEffect(() => {
getTeamDetail(teamId as string)
Expand All @@ -68,7 +69,7 @@ const TeamDetail = () => {
.catch((error) => {
setError({ error: { message: error.message, code: '500' } })
})
}, [teamId, prepTeamData])
}, [prepTeamData])

// required for breadcrumb
useEffect(() => {
Expand Down
7 changes: 4 additions & 3 deletions src/pages/UserProfile/UserProfile.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable react-hooks/exhaustive-deps */
import styles from './userprofile.module.scss'

import { Dialog, Text, Link, LeadParagraph } from '@statisticsnorway/ssb-component-library'
Expand Down Expand Up @@ -53,7 +54,7 @@ const UserProfile = () => {
.catch((error) => {
setError({ error: { message: error.message, code: '500' } })
})
}, [principalName])
}, [])

useEffect(() => {
if (userProfileData) {
Expand All @@ -70,7 +71,7 @@ const UserProfile = () => {
setError({ error: { message: error.message, code: '500' } })
})
}
}, [userProfileData, principalName, prepTeamData])
}, [prepTeamData])

// required for breadcrumb
useEffect(() => {
Expand All @@ -79,7 +80,7 @@ const UserProfile = () => {
userProfileData.display_name = displayName
setBreadcrumbUserProfileDisplayName({ displayName })
}
}, [userProfileData, setBreadcrumbUserProfileDisplayName])
}, [setBreadcrumbUserProfileDisplayName])

const renderTeamNameColumn = (team: Team) => {
return (
Expand Down

0 comments on commit 1207f8d

Please sign in to comment.