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