Skip to content

Commit 3a6c9a3

Browse files
authored
Merge pull request #271 from ItRecode/FE-260
[FE-260] feat: 성능 최적화
2 parents ba29dc4 + d2dbbac commit 3a6c9a3

20 files changed

Lines changed: 253 additions & 248 deletions

src/components/BackButton.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,11 @@ import React from 'react'
22
import { ReactComponent as Back } from '@assets/back.svg'
33
import { useNavigate } from 'react-router-dom'
44

5-
function BackButton({ onClick }: { onClick?: () => void }) {
5+
const BackButton = React.memo(function BackBtn({
6+
onClick,
7+
}: {
8+
onClick?: () => void
9+
}) {
610
const navigate = useNavigate()
711

812
const handleLocateBack = () => {
@@ -18,6 +22,6 @@ function BackButton({ onClick }: { onClick?: () => void }) {
1822
}
1923

2024
return <Back className="cursor-pointer" onClick={handleLocateBack} />
21-
}
25+
})
2226

2327
export default BackButton

src/components/Chip.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,13 @@ function Chip({
4848
`}
4949
>
5050
{icon && (
51-
<img className="mr-2 aspect-square w-[14px] object-cover" src={icon} />
51+
<div className="mr-2 aspect-square w-[14px]">
52+
<img
53+
className="h-full w-full object-cover"
54+
src={icon}
55+
alt={message}
56+
/>
57+
</div>
5258
)}
5359
<p className="flex items-center text-[14px] leading-none">{message}</p>
5460
</button>

src/components/Navbar.tsx

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
1-
import React from 'react'
1+
import React, { Suspense } from 'react'
22
import { ReactComponent as Record_icon } from '@assets/nav_icons/record_icon.svg'
33
import { Outlet, useNavigate } from 'react-router-dom'
44
import NavbarItem from './NavbarItem'
5+
import Loading from './Loading'
56

6-
export default function NavBar() {
7+
function NavBar() {
78
const navigate = useNavigate()
89

910
return (
1011
<>
11-
<Outlet />
12+
<Suspense fallback={<Loading />}>
13+
<Outlet />
14+
</Suspense>
1215
<nav className="fixed bottom-0 z-20 flex h-[60px] w-full max-w-[420px] justify-between rounded-t-xl border border-solid border-grey-3 bg-white px-3 pt-1.5">
1316
<nav className="left-3 flex">
1417
<NavbarItem pageName="홈" linkSrc="/" className="mr-5" />
@@ -30,3 +33,5 @@ export default function NavBar() {
3033
</>
3134
)
3235
}
36+
37+
export const MemoizedNavbar = React.memo(NavBar)

src/components/NavbarItem.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,24 +43,28 @@ export default function NavbarItem({
4343
return (
4444
<Home_icon
4545
className={`${iconFormat} ${checkPathWithIconImg(linkSrc)}`}
46+
aria-label={pageName}
4647
/>
4748
)
4849
case '/collect':
4950
return (
5051
<Rank_icon
5152
className={`${iconFormat} ${checkPathWithIconImg(linkSrc)}`}
53+
aria-label={pageName}
5254
/>
5355
)
5456
case '/myrecord':
5557
return (
5658
<MyRecord_icon
5759
className={`${iconFormat} ${checkPathWithIconImg(linkSrc)}`}
60+
aria-label={pageName}
5861
/>
5962
)
6063
case '/setting':
6164
return (
6265
<Setting_icon
6366
className={`${iconFormat} ${checkPathWithIconImg(linkSrc)}`}
67+
aria-label={pageName}
6468
/>
6569
)
6670
}

src/components/ParrentCategoryTab.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { CELEBRATION_ID, CONSOLATION_ID } from '@assets/constant/constant'
22
import React, { Dispatch, SetStateAction } from 'react'
33
import { parentCategoryID } from 'types/category'
44

5-
export default function ParentCategoryTab({
5+
const MemoizedParentCategoryTab = React.memo(function ParentCategoryTab({
66
parentCategoryId,
77
setParentCategoryId,
88
isModify,
@@ -60,4 +60,6 @@ export default function ParentCategoryTab({
6060
<hr className="m-0 h-[1px] border-0 bg-grey-3" />
6161
</>
6262
)
63-
}
63+
})
64+
65+
export default MemoizedParentCategoryTab

src/components/RecordCard.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,9 @@ function RecordCard({
4343
} shrink-0 rounded-2xl ${ColorName} flex cursor-pointer flex-col items-center justify-center`}
4444
onClick={() => handleClickRecord(recordId)}
4545
>
46-
<RecordIcon width={100} height={100} />
46+
<div className="aspect-square w-[100px]">
47+
<RecordIcon className="h-full w-full" />
48+
</div>
4749
<div className="mt-4 w-full text-sm font-semibold text-grey-10">
4850
<p className="w-full truncate px-5 text-center">{title}</p>
4951
</div>

src/components/Spinner.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ interface ISpinnerProps {
55
size?: 'small' | 'large' | 'button'
66
}
77

8-
export default function Spinner({ size = 'small' }: ISpinnerProps) {
8+
const Spinner = React.memo(function SpinnerComponent({
9+
size = 'small',
10+
}: ISpinnerProps) {
911
const setSpinnerSize = (size: string) => {
1012
switch (size) {
1113
case 'small':
@@ -18,4 +20,6 @@ export default function Spinner({ size = 'small' }: ISpinnerProps) {
1820
}
1921

2022
return <SpinnerIcon className={`z-10 animate-spin ${setSpinnerSize(size)}`} />
21-
}
23+
})
24+
25+
export default Spinner

src/pages/AddRecord/AddRecord.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ import { useQuery } from '@tanstack/react-query'
1818
import Loading from '@components/Loading'
1919
import { parentCategoryID } from 'types/category'
2020
import { CELEBRATION_ID } from '@assets/constant/constant'
21-
import ParentCategoryTab from '@components/ParrentCategoryTab'
2221
import AddRecordTitle from './AddRecordTitle'
2322
import AddRecordInput from './AddRecordInput'
2423
import { useCheckMobile } from '@hooks/useCheckMobile'
24+
import MemoizedParentCategoryTab from '@components/ParrentCategoryTab'
2525

2626
export type IsInputsHasValueType = {
2727
input: boolean
@@ -240,7 +240,7 @@ export default function AddRecord() {
240240
isModify && 'pointer-events-none'
241241
} sticky top-0 left-0 z-[5] bg-grey-1`}
242242
>
243-
<ParentCategoryTab
243+
<MemoizedParentCategoryTab
244244
parentCategoryId={parentCategoryId}
245245
setParentCategoryId={setParentCategoryId}
246246
isModify={isModify}

src/pages/AddRecord/AddRecordFile.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,8 +144,10 @@ function AddRecordFile({
144144
<div className="mb-8 flex items-center gap-2">
145145
{isToast && makeToast()}
146146
<label className="h-[66px] w-[66px]" htmlFor="file">
147-
<div className="mr-4 flex h-[66px] w-[66px] flex-col items-center justify-center rounded-2xl border-2 border-dashed border-grey-4 py-3 px-5">
148-
<img className=" mb-1" src={Camera} alt="camera" />
147+
<div className="mr-4 flex h-[66px] w-[66px] flex-col items-center justify-center rounded-2xl border-2 border-dashed border-grey-4 py-3 px-5">
148+
<div className="mb-1 h-[24px] w-[24px]">
149+
<img className="h-full w-full" src={Camera} alt="camera" />
150+
</div>
149151
<p className=" text-xs text-grey-4">
150152
<span
151153
className={`${!currentImg ? 'text-grey-4' : 'text-primary-2'}`}

src/pages/Collect/CollectRanking.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { CELEBRATION_ID } from '@assets/constant/constant'
22
import Category from '@components/Category'
3-
import ParentCategoryTab from '@components/ParrentCategoryTab'
43
import React, { Dispatch, SetStateAction, useEffect, useState } from 'react'
54
import { parentCategoryID } from 'types/category'
65
import { ReactComponent as Collapse } from '@assets/collect_page_icon/collapse.svg'
@@ -17,6 +16,7 @@ import {
1716
} from '@store/collectPageAtom'
1817
import { checkFromDetailPage } from '@store/detailPageAtom'
1918
import RankingItemNoData from '@components/RankingItemNoData'
19+
import MemoizedParentCategoryTab from '@components/ParrentCategoryTab'
2020

2121
export default function CollectRanking({
2222
setOpenModal,
@@ -100,7 +100,7 @@ export default function CollectRanking({
100100
</div>
101101

102102
<section id="parentCategory" className="mt-[22px]">
103-
<ParentCategoryTab
103+
<MemoizedParentCategoryTab
104104
parentCategoryId={parentCategoryId}
105105
setParentCategoryId={setParentCategoryId}
106106
/>

0 commit comments

Comments
 (0)