Thinking in React
Last updated
Last updated
๋ฆฌ์กํธ ๊ณต์ ๋ฌธ์์ ์๊ฐ๋ ๐ Thinking in React ์์ ๋ฅผ ํตํ ์ฝ๋ ์ค์ต
step 0
Start with the mockup๊ฐ๋ฐ ํ๊ฒฝ ์ธํ (vite)
Thinking in React ์์ ์ ์ ์ ์กฐ๊ฑด ๋ฐ Mockup ํ์
Mockup ๊ณผ JSON ํ์์ API ํ์ธ ํ โ ์ฌ์ฉ์๊ฐ ๋ณผ ์ ์๋๋ก UI ์ค๊ณ
step 1
Build a static version in ReactStatic Version UI ๊ตฌํ (ํผ๋ธ๋ฆฌ์ฑ ์์ )
JSON ์์ ์นดํ ๊ณ ๋ฆฌ์ value ๊ฐ์ ์ถ์ถ โ reduce ๋ฉ์๋๋ฅผ ํตํด
step 1
Break the UI into a component hierarchyUI๋ฅผ ๊ตฌ์ฑ ์์ ๊ณ์ธต ๊ตฌ์กฐ๋ก ๋๋๊ธฐ (์ปดํฌ๋ํธ ๊ตฌ์ฑ)
JSON API ๊ธฐ๋ฐ์ผ๋ก UI ๊ตฌํํ๋, ๋ฐ๋ณต์ ์ธ ์์๊ฐ ๋ณด์ฌ์ง๊ณ ์ฝ๋๊ฐ ๊ธธ์ด์ง โ table tbody ์์ญ ์ปดํฌ๋ํธ๋ก ๋ถ๋ฆฌ ProductsInCategory
ProductInCategory
์ปดํฌ๋ํธ๋ฅผ ๋ถ๋ฆฌํ๊ณ ๋ณด๋, ๋ฐ๋ณต์ ์ธ ์์ ๋ฐ๊ฒฌ โ ProductRow
ProductCategoryRow
์ปดํฌ๋ํธ ๋ถ๋ฆฌ
ProductTable
์ปดํฌ๋ํธ๋ฅผ ์์ฑํด์ table ์์ญ ์ ์ฒด ๋งตํ
๊ฒ์ ์์ญ SearchBar
์ปดํฌ๋ํธ๋ก ๋ถ๋ฆฌ
FilterableProductTable
table ๊ณผ ๊ฒ์ ์์ญ ์ ์ฒด ๋งตํ
SearchBar
๋ถ๋ฆฌํ๊ณ ์ฒดํฌ๋ฐ์ค field CheckBoxField
์ปดํฌ๋ํธ ๋ถ๋ฆฌ
SearchBar
์ปดํฌ๋ํธ์์ ์ถ๊ฐ๋ก input field TextField
์ปดํฌ๋ํธ ๋ถ๋ฆฌ
5.FilterableProductTable
4.SearchBar
7.TextField
6.CheckBoxField
3.ProductTable
1.ProductsInCategory
2.ProductCategoryRow
2.ProductRow
step 3
Find the minimal but complete representation of UI statestate(์ํ)๊ฐ ํ์ํ ๋ถ๋ถ์ ์๋ณ
์๋ ์ ํ ๋ชฉ๋ก (props)
์ฌ์ฉ์๊ฐ ์
๋ ฅํ ๊ฒ์์ด (state) TextField
์ฒดํฌ๋ฐ์ค์ ๊ฐ (state) CheckBoxField
ํํฐ๋ง๋ ์ ํ ๋ชฉ๋ก (props)
step 4
Identify where your state should livestate(์ํ)๋ฅผ ์๋ณ ํ ํ state(์ํ)์ ๊ณตํต ์์ ์์๋ฅผ ์ฐพ์ state(์ํ)์ ์์น ๊ฒฐ์
state(์ํ)๊ฐ ๊ณต์ ๋์ด์ผ ํ๋ ๊ณตํต ์์ ์ปดํฌ๋ํธ FilterableProductTable
step 5
Add inverse data flowstate(์ํ)๋ฅผ ์ ๋ฐ์ดํธ ํ๊ธฐ ์ํ ์ฝ๋ฐฑํจ์๋ฅผ ์ญ๋ฐฉํฅ์ผ๋ก ๋์ด์ฌ๋ฆฌ๊ธฐ
์ฌ์ฉ์๊ฐ ์
๋ ฅํ ๊ฒ์์ด (state) TextField
์ฒดํฌ๋ฐ์ค์ ๊ฐ (state) CheckBoxField
์ปดํฌ๋ํธ์์ useState๋ก ์์ฑํ state ๋์ด์ฌ๋ ค ๊ณต์ ์ปดํฌ๋ํธ์ ์์น ์ํค๊ณ , props๋ฅผ ํตํด ํ์ ์ปดํฌ๋ํธ์๊ฒ state์ state ๋ณ๊ฒฝํ๊ธฐ ์ํจ ํจ์๋ฅผ ์ ๋ฌ