Thinking in React
학습 내용
리액트 공식 문서에 소개된 🔗 Thinking in React 예제를 통한 코드 실습
Thinking in React
1. step 0
Start with the mockup
step 0
Start with the mockup개발 환경 세팅 (vite)
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 메서드를 통해
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