Thinking in React
ํ์ต ๋ด์ฉ
๋ฆฌ์กํธ ๊ณต์ ๋ฌธ์์ ์๊ฐ๋ ๐ Thinking in React ์์ ๋ฅผ ํตํ ์ฝ๋ ์ค์ต
Thinking in React
1. step 0
Start with the mockup
step 0
Start with the mockup๊ฐ๋ฐ ํ๊ฒฝ ์ธํ (vite)
npm create vite@latest
Thinking in React ์์ ์ ์ ์ ์กฐ๊ฑด ๋ฐ Mockup ํ์
Mockup ๊ณผ JSON ํ์์ API ํ์ธ ํ โ ์ฌ์ฉ์๊ฐ ๋ณผ ์ ์๋๋ก UI ์ค๊ณ

2. step 1
Build a static version in React
step 1
Build a static version in ReactStatic Version UI ๊ตฌํ (ํผ๋ธ๋ฆฌ์ฑ ์์ )
JSON ์์ ์นดํ ๊ณ ๋ฆฌ์ value ๊ฐ์ ์ถ์ถ โ reduce ๋ฉ์๋๋ฅผ ํตํด
[
{ category: "Fruits", price: "$1", stocked: true, name: "Apple" },
{ category: "Fruits", price: "$1", stocked: true, name: "Dragonfruit" },
{ category: "Fruits", price: "$2", stocked: false, name: "Passionfruit" },
{ category: "Vegetables", price: "$2", stocked: true, name: "Spinach" },
{ category: "Vegetables", price: "$4", stocked: false, name: "Pumpkin" },
{ category: "Vegetables", price: "$1", stocked: true, name: "Peas" }
]
const categories = products.reduce(
(acc: string[], product: Product) =>
acc.includes(product.category) ? acc : [...acc, product.category],
[]
);
3. step 1
Break the UI into a component hierarchy
step 1
Break the UI into a component hierarchyUI๋ฅผ ๊ตฌ์ฑ ์์ ๊ณ์ธต ๊ตฌ์กฐ๋ก ๋๋๊ธฐ (์ปดํฌ๋ํธ ๊ตฌ์ฑ)
JSON API ๊ธฐ๋ฐ์ผ๋ก UI ๊ตฌํํ๋, ๋ฐ๋ณต์ ์ธ ์์๊ฐ ๋ณด์ฌ์ง๊ณ ์ฝ๋๊ฐ ๊ธธ์ด์ง โ table tbody ์์ญ ์ปดํฌ๋ํธ๋ก ๋ถ๋ฆฌ
ProductsInCategory
ProductInCategory
์ปดํฌ๋ํธ๋ฅผ ๋ถ๋ฆฌํ๊ณ ๋ณด๋, ๋ฐ๋ณต์ ์ธ ์์ ๋ฐ๊ฒฌ โProductRow
ProductCategoryRow
์ปดํฌ๋ํธ ๋ถ๋ฆฌProductTable
์ปดํฌ๋ํธ๋ฅผ ์์ฑํด์ table ์์ญ ์ ์ฒด ๋งตํ๊ฒ์ ์์ญ
SearchBar
์ปดํฌ๋ํธ๋ก ๋ถ๋ฆฌFilterableProductTable
table ๊ณผ ๊ฒ์ ์์ญ ์ ์ฒด ๋งตํSearchBar
๋ถ๋ฆฌํ๊ณ ์ฒดํฌ๋ฐ์ค fieldCheckBoxField
์ปดํฌ๋ํธ ๋ถ๋ฆฌSearchBar
์ปดํฌ๋ํธ์์ ์ถ๊ฐ๋ก input fieldTextField
์ปดํฌ๋ํธ ๋ถ๋ฆฌ
5.FilterableProductTable
4.SearchBar
7.TextField
6.CheckBoxField
3.ProductTable
1.ProductsInCategory
2.ProductCategoryRow
2.ProductRow

4. step 3
Find the minimal but complete representation of UI state
step 3
Find the minimal but complete representation of UI statestate(์ํ)๊ฐ ํ์ํ ๋ถ๋ถ์ ์๋ณ
์๋ ์ ํ ๋ชฉ๋ก (props)
์ฌ์ฉ์๊ฐ ์ ๋ ฅํ ๊ฒ์์ด (state)
TextField
์ฒดํฌ๋ฐ์ค์ ๊ฐ (state)
CheckBoxField
ํํฐ๋ง๋ ์ ํ ๋ชฉ๋ก (props)
5. step 4
Identify where your state should live
step 4
Identify where your state should livestate(์ํ)๋ฅผ ์๋ณ ํ ํ state(์ํ)์ ๊ณตํต ์์ ์์๋ฅผ ์ฐพ์ state(์ํ)์ ์์น ๊ฒฐ์
state(์ํ)๊ฐ ๊ณต์ ๋์ด์ผ ํ๋ ๊ณตํต ์์ ์ปดํฌ๋ํธ
FilterableProductTable
6. step 5
Add inverse data flow
step 5
Add inverse data flowstate(์ํ)๋ฅผ ์ ๋ฐ์ดํธ ํ๊ธฐ ์ํ ์ฝ๋ฐฑํจ์๋ฅผ ์ญ๋ฐฉํฅ์ผ๋ก ๋์ด์ฌ๋ฆฌ๊ธฐ
์ฌ์ฉ์๊ฐ ์ ๋ ฅํ ๊ฒ์์ด (state)
TextField
์ฒดํฌ๋ฐ์ค์ ๊ฐ (state)
CheckBoxField
์ปดํฌ๋ํธ์์ useState๋ก ์์ฑํ state ๋์ด์ฌ๋ ค ๊ณต์ ์ปดํฌ๋ํธ์ ์์น ์ํค๊ณ , props๋ฅผ ํตํด ํ์ ์ปดํฌ๋ํธ์๊ฒ state์ state ๋ณ๊ฒฝํ๊ธฐ ์ํจ ํจ์๋ฅผ ์ ๋ฌ
Last updated