-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
๐ [#3] Online Store Renewal Retrospective ์ํฐํด์ ์ถ๊ฐํ๋ค
- Loading branch information
1 parent
ef2f47a
commit 4ef7e39
Showing
1 changed file
with
149 additions
and
0 deletions.
There are no files selected for viewing
149 changes: 149 additions & 0 deletions
149
contents/articles/online-store-renewal-retrospective.mdx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,149 @@ | ||
--- | ||
title: ์จ๋ผ์ธ ์คํ ์ด ์ ๊ท ํ์ด์ง ๋ฆฌ๋ด์ผ ํ๋ก์ ํธ ํ๊ณ | ||
description: ๋ก์ปฌ์ค๋ผ์ดํ์ ์จ๋ผ์ธ ์คํ ์ด๋ฅผ ๋ฆฌ๋ด์ผ ๊ธฐ์ ๊ณผ์ | ||
createdAt: 2022-09-05 | ||
category: React | ||
tags: | ||
- React | ||
- TypeScript | ||
- Team Project | ||
- Retrospective | ||
- Wanted PreOnBoarding Frontend Course | ||
--- | ||
|
||
## ์์ | ||
|
||
https://github.com/wanted-pre-onboarding-fe-6th-team2/pre-onboarding-assignment-week-1-2-team-2 | ||
|
||
[ํ๋ฃจ๋ผ-์ค๋๋ํ๋ฃปํด!](https://fruitte-renewal.netlify.app/) | ||
|
||
์ด๋ฒ ๊ณผ์ ๋ ๊ธฐ์กด ์ด์ ์๋น์ค์ธ ์จ๋ผ์ธ ์คํ ์ด์ ์ ๊ท ํ์ด์ง๋ฅผ ์ ์ํ๋ ๊ณผ์ ์ด๋ค. API๊ฐ ์กด์ฌํ์ง ์๊ธฐ ๋๋ฌธ์ ๋๋ฏธ ๋ฐ์ดํฐ๋ก ์์ ์ ์งํํด์ผ ํ๋ค๋ ์ ์ด ์กฐ๊ธ ์์ฌ์ ๋ค. API ํธ์ถ์ ํ๋ฉด ์ต์ ํ๋ผ๋์ง ๊ด์ฌ์ฌ์ ๋ถ๋ฆฌ๋ฅผ ์ํ ์ฝ๋ ๋ถ๋ฆฌ๋ผ๋์ง ํ์ตํ๋ฉด์ ์ฝ๋๋ฅผ ์ด๋ป๊ฒ ํ๋ฉด ๋ ๊น๋ํ๊ฒ ์์ฑํ ์ง ๊ณ ๋ฏผํ ์ ์๊ธฐ ๋๋ฌธ์ด๋ค. | ||
|
||
[ํ๋ฃป์คํ ์ด](https://www.fruitte.co.kr/fruitstore) | ||
|
||
์๋ฌดํผ ์๋ ๊ฑด ์ด๋ฏธ ์๋ ๊ฒ์ด๋๊น ์งํํ๊ธฐ๋ก ํ๊ณ ํ์๋ค๊ณผ ๋ด๋น ์์ ์ ๋๋ ํ์ ์ํ ๋ชฉ๋ก ํ์ด์ง๋ฅผ ๋ด๋นํ๊ฒ ๋๋ค. | ||
|
||
## ์๊ตฌ์ฌํญ ๋ถ์ | ||
|
||
์ํ ๋ชฉ๋ก ํ์ด์ง๋ ํฌ๊ฒ ๋ ๊ฐ์ง๋ฅผ ๊ตฌํํด์ผ ํ๋ค. | ||
|
||
- ์ํ ๋ชฉ๋ก์ UI | ||
- 10๊ฐ ๋จ์์ ํ์ด์ง๋ค์ด์ | ||
|
||
์ํ ๋ชฉ๋ก UI์ ๊ฒฝ์ฐ์๋ ๊ฒฐ๊ตญ `map`์ ํ์ฉํด ์ํ ๋ชฉ๋ก ์์ดํ ์ปดํฌ๋ํธ๋ฅผ ๋ ๋๋งํด์ฃผ๋ฉด ๋๊ธฐ ๋๋ฌธ์ ๋ณ๋ค๋ฅธ ์ด์๋ ๋ฌธ์ ๋ ์ํฉ์ ์์ ๊ฒ์ด๋ผ๊ณ ์์ํ๋ค. ๋ค๋ง, 10๊ฐ ๋จ์์ ํ์ด์ง๋ค์ด์ ๊ธฐ๋ฅ์ ๊ฒฝ์ฐ API ํธ์ถ์ `page`, `limit`๋ฅผ ๋๊ฒจ์ฃผ๋ ๋ฐฉ์์ ๊ตฌํํด๋ดค์ง๋ง, API ํธ์ถ ์์ด ๊ตฌํํด์ผํ๊ธฐ์ ์ด๋ค ๋ฐฉ์์ผ๋ก ์งํํด์ผ ํ๋์ง ๊ณ ๋ฏผ์ด ์์๋ค. | ||
|
||
## API ์๋ ํ์ด์ง๋ค์ด์ ๊ตฌํํ๊ธฐ | ||
|
||
ํ์ด์ง๋ค์ด์ ์ ์๊ณ ๋ฆฌ์ฆ ์์ฒด๋ฅผ ์๊ณ ์์ผ๋ฉด ์ดํ์ ์ด๋์๋ ํ์ฉํ ์ ์์ ๊ฑฐ๋ผ๊ณ ์๊ฐํ๋ค. ํ์ด์ง๋ค์ด์ ์ ๋ก์ง์์ `page`์ `limit`๋ฅผ ํ์ฉํด ์ํ ๋ฐฐ์ด์์ ์ผ๋ถ๋ฅผ ์๋ผ๋ด๋ ๊ฒ์ด ๊ฐ์ฅ ์ค์ํ๋ค. ์๋ฅผ ๋ค์ด, `page`๊ฐ `2`์ด๊ณ `limit`๊ฐ `10`์ด๋ผ๋ฉด, 11๋ฒ์งธ ์ํ๋ถํฐ 20๋ฒ์งธ ์ํ๊น์ง๋ฅผ ์๋ผ์ ๊ฐ์ ธ์ค๋ ๊ฒ์ด๋ค. | ||
|
||
๊ฒฐ๊ตญ, API์ ๋๊ฒจ์ฃผ๋ `page`, `limit`๋ฅผ `state`๋ก ์ฒ๋ฆฌํ์ฌ ๊ตฌํํ๋ฉด ๋ ๊ฒ ๊ฐ๋ค๋ ์๊ฐ์ ํ๋ค. ๋ฐ๋ผ์ ํ์ด์ง๋ค์ด์ ์ ํ๋์ ์ปดํฌ๋ํธ๋ก ๊ตฌํํ๊ณ , ํด๋น ์ปดํฌ๋ํธ๋ฅผ ์ํ ๋ชฉ๋ก ์ปดํฌ๋ํธ ์์์ ๋๋ฉด ๋ ๊ฒ์ด๋ผ๊ณ ์๊ฐํ๋ค. | ||
|
||
```jsx | ||
// common/Pagination/Pagination.jsx | ||
|
||
import React, { useState, Children, isValidElement, cloneElement } from 'react'; | ||
import PaginationButton from '@/components/common/Pagination/PaginationButton'; | ||
import * as Styled from '@/components/common/Pagination/Pagination.styled'; | ||
|
||
const Pagination = ({ data, children }) => { | ||
// 1 page๋ฅผ ๊ธฐ๋ณธ๊ฐ์ผ๋ก ์ค์ | ||
const [currentPage, setCurrentPage] = useState(1); | ||
|
||
// 10๊ฐ๋ฅผ limit๋ก ํจ | ||
const itemsPerPage = 10; | ||
|
||
// ์ฆ, page์ limit๋ฅผ ์กฐํฉํ์ฌ ์ธ๋ฑ์ฑ ์ฒ๋ฆฌํ๊ธฐ | ||
const indexOfLast = currentPage * itemsPerPage; | ||
const indexOfFirst = indexOfLast - itemsPerPage; | ||
|
||
// ํ์ด์ง๋ค์ด์ ๋ก์ง์ ๋ง๊ฒ ๋ฐฐ์ด ์๋ฅด๊ธฐ | ||
const currentItems = items => { | ||
let currentItems = 0; | ||
currentItems = items.slice(indexOfFirst, indexOfLast); | ||
return currentItems; | ||
}; | ||
|
||
return (); | ||
}; | ||
|
||
export default Pagination; | ||
``` | ||
|
||
๊ฒฐ๊ตญ ์ํ๋ ๋๋ก ํ์ด์ง๋ค์ด์ ๋ก์ง์ฒ๋ผ ์ํ ๋ชฉ๋ก์ ๋ฐฐ์ด์ ๋๋๋๋ฐ์๋ ์ฑ๊ณตํ์ง๋ง, Props๋ ์ฝ๊ธฐ ์ ์ฉ์ด๊ธฐ์ ์์ ํ ์ ์์ผ๋ฏ๋ก children ์ปดํฌ๋ํธ์ ์ถ๊ฐ์ ์ธ Props๋ก ์ ๋ฌํ ์๊ฐ ์์๋ค. [React ๊ณต์ ๋ฌธ์](https://ko.reactjs.org/docs/react-api.html#cloneelement)๋ฅผ ๋ณด๋ฉด children ์ปดํฌ๋ํธ๋ฅผ `[React.cloneElement](https://ko.reactjs.org/docs/react-api.html#cloneelement)`๋ก ๋ณต์ ํ์ฌ Props๋ฅผ ์ถ๊ฐํ๊ณ ์ด๋ฅผ ๋ฐํํ ์ ์๊ฒ ๋์ด ์์ด, ์ด๋ฅผ ํ์ฉํด JSX๋ฅผ ๋ฐํํ์ฌ ์ถํ ๋ค๋ฅธ ํ์ด์ง์์์ ํ์ด์ง๋ค์ด์ ์ ์ฝ๊ฒ ํ์ฉํ ์ ์๊ฒ ํ๋ค. | ||
|
||
```jsx | ||
// common/Pagination/Pagination.jsx | ||
|
||
import React, { useState, Children, isValidElement, cloneElement } from 'react'; | ||
import PaginationButton from '@/components/common/Pagination/PaginationButton'; | ||
import * as Styled from '@/components/common/Pagination/Pagination.styled'; | ||
|
||
const Pagination = ({ data, children }) => { | ||
// 1 page๋ฅผ ๊ธฐ๋ณธ๊ฐ์ผ๋ก ์ค์ | ||
const [currentPage, setCurrentPage] = useState(1); | ||
|
||
// 10๊ฐ๋ฅผ limit๋ก ํจ | ||
const itemsPerPage = 10; | ||
|
||
// ์ฆ, page์ limit๋ฅผ ์กฐํฉํ์ฌ ์ธ๋ฑ์ฑ ์ฒ๋ฆฌํ๊ธฐ | ||
const indexOfLast = currentPage * itemsPerPage; | ||
const indexOfFirst = indexOfLast - itemsPerPage; | ||
|
||
// ํ์ด์ง๋ค์ด์ ๋ก์ง์ ๋ง๊ฒ ๋ฐฐ์ด ์๋ฅด๊ธฐ | ||
const currentItems = (items) => { | ||
let currentItems = 0; | ||
currentItems = items.slice(indexOfFirst, indexOfLast); | ||
return currentItems; | ||
}; | ||
|
||
return ( | ||
<Styled.PaginationSection> | ||
** | ||
{cloneElement(children, { | ||
data: currentItems(data), | ||
page: currentPage, | ||
totalItemNumber: data.length, | ||
})} | ||
** | ||
<PaginationButton | ||
itemsPerPage={itemsPerPage} | ||
totalItemNumber={data.length} | ||
page={currentPage} | ||
paginate={setCurrentPage} | ||
/> | ||
</Styled.PaginationSection> | ||
); | ||
}; | ||
|
||
export default Pagination; | ||
``` | ||
|
||
๋ฌผ๋ก , `limit`๋ฅผ Props๋ก ์ฒ๋ฆฌํ์ฌ ๊ธฐ์ค ๊ฐ์๋ฅผ ๋ณ๊ฒฝํ ์ ์๊ฒ ํ๋ ๊ฒ์ด ์กฐ๊ธ ๋ ์ฌ์ฌ์ฉ์ฑ์ ๋์์ด ๋ ๊ฒ ๊ฐ๋ค. | ||
|
||
```jsx | ||
const Pagination = ({ data, limit, children }) => { | ||
// 1 page๋ฅผ ๊ธฐ๋ณธ๊ฐ์ผ๋ก ์ค์ | ||
const [currentPage, setCurrentPage] = useState(1); | ||
|
||
// limit๋ฅผ props๋ก ๋ฐ์์ด | ||
const itemsPerPage = limit; | ||
|
||
// ... | ||
``` | ||
## ๊ธฐ์กด ์คํ ์ด ๊ฐ์ ์ | ||
- ๊ธฐ์กด ์น์ฌ์ดํธ์ ๊ฒฝ์ฐ, ๋ชจ๋ ์ํ ๋ชฉ๋ก์ ๋ ๋๋ง๋๊ธฐ ๋๋ฌธ์ ์ถํ ์คํ ์ด์ ๋ ๋ง์ ์ํ์ด ์ ์ ๋ ๊ฒฝ์ฐ์ ์ ์ฒด ๋ ๋๋ง ์๊ฐ์ด ์ค๋ ๊ฑธ๋ฆด ๊ฒ์ ๊ณ ๋ คํ์ฌ ํ์ด์ง๋ค์ด์ ๋ก์ง์ ์ถ๊ฐํด ์ฌ์ฉ์์ ๋๊ธฐ ์๊ฐ๊ณผ ์๋ฒ์ ๋ก๋ ์๊ฐ์ ์ค์๋ค. | ||
- ํ์ด์ง๋ค์ด์ ๋ก์ง์ ๋ถ๋ฆฌํ์ฌ ๋ค๋ฅธ ํ์ด์ง์์๋ ์ฌ์ฉํ ์ ์๊ฒ ํ์ฅ์ฑ๊ณผ ์ฌ์ฌ์ฉ์ฑ์ ๊ณ ๋ คํ์ฌ ์์ ํ๋ค. | ||
- ์ํ ์ ๋ชฉ ๋ฑ UI๊ฐ ๊นจ์ง๋ ๋ถ๋ถ์ ๊ฐ์ ํ๊ณ , ์์ ์ด๋ฏธ์ง ์ ๋๋ฉ์ด์ ์ ์ถ๊ฐํด UI๋ฅผ ์กฐ๊ธ ๋ ๋ถ๋๋ฝ๊ฒ ๋ง๋ค์๋ค. | ||
- UX๋ฅผ ๋์ด๊ธฐ ์ํด ์ํ ๋ชฉ๋ก ํ์ด์ง์์ ์ข์์ ๋ฒํผ์ ์ถ๊ฐํ๋ค. | ||
## ๋ง๋ฌด๋ฆฌ | ||
๊ธฐ๋ณธ์ ํด๋นํ๋ ๋ชฉ๋ก ํ์ด์ง๋ฅผ ๊ตฌํํ๋ฉด์ ํ์ด์ง๋ค์ด์ ๋ก์ง์ ์ง์ ๊ตฌํํด๋ณด๋ ์กฐ๊ธ ๋ ๊น์ด ์ดํดํ ์ ์๋ ์ข์ ๊ณผ์ ์๋ค. UI/UX๋ฅผ ๊ณ ๋ คํ๋ฉด์ Emotion์ผ๋ก ์์ ์ ์งํํ๋ฉด์ ์ด๋ค ๋ถ๋ถ์ด ์ด๋ป๊ฒ ์ฌ์ฉ์์๊ฒ ์ํฅ์ ๋ฏธ์น ์ง ๊ณ ๋ฏผํ๋๋ฐ, ์์ง ์ด๋ฌํ ๋ถ๋ถ์์๋ ๋ถ์กฑํ ๊ฒ ๊ฐ์์ ์ถํ์ UX ๊ด๋ จํด์ ํ์ตํ๋ ๊ฒ๋ ์ข์ ๊ฒ ๊ฐ๋ค. | ||
๋! ๐๐ปโโ๏ธ | ||
## ์ฐธ๊ณ ์๋ฃ | ||
- **[React cloneElement()](https://ko.reactjs.org/docs/react-api.html#cloneelement)** |