-
Notifications
You must be signed in to change notification settings - Fork 28
[4단계 미션] 박예은 미션 제출합니다 #28
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
fe6716b
e58cc30
57849c4
16b7b7f
efed817
c3c5fc7
6c6c45b
972cf6e
8e5e16b
8794dae
80dce59
e02a97a
29016c0
f41ced4
19d8f6e
b73b1f5
d364767
71bffb8
cc49523
c6721b7
7124439
c7e8c08
f25a0fd
9e06b51
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,26 +1,20 @@ | ||||||||||||||||||||||||||||||||
| import "../styles/AddRestaurantModalStyle.css"; | ||||||||||||||||||||||||||||||||
| import { CATEGORY_DATA } from "../data/categoryData"; | ||||||||||||||||||||||||||||||||
| import restaurantsData from "../data/restaurantsData"; | ||||||||||||||||||||||||||||||||
| import { useState } from "react"; | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| function AddRestaurantModal({ setIsAddModalOpen }) { | ||||||||||||||||||||||||||||||||
| const [selectedCategory, setSelectedCategory] = useState(""); | ||||||||||||||||||||||||||||||||
| function AddRestaurantModal({ setIsAddModalOpen, handleAddRestaurant }) { | ||||||||||||||||||||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
깔끔하고 직관적인 이름이네요 👁️ |
||||||||||||||||||||||||||||||||
| const [newRestaurant, setNewRestaurant] = useState({ | ||||||||||||||||||||||||||||||||
| id: Date.now(), | ||||||||||||||||||||||||||||||||
| name: "", | ||||||||||||||||||||||||||||||||
| description: "", | ||||||||||||||||||||||||||||||||
| category: "", | ||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| const handleAddBtnClick = () => { | ||||||||||||||||||||||||||||||||
| event.preventDefault(); | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| restaurantsData.push({ | ||||||||||||||||||||||||||||||||
| id: Date.now(), | ||||||||||||||||||||||||||||||||
| name: restaurantName, | ||||||||||||||||||||||||||||||||
| description: restaurantInfo, | ||||||||||||||||||||||||||||||||
| category: selectedCategory, | ||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||
| handleAddRestaurant(newRestaurant); | ||||||||||||||||||||||||||||||||
| setIsAddModalOpen(false); | ||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| const [restaurantName, setRestaurantName] = useState(""); | ||||||||||||||||||||||||||||||||
| const [restaurantInfo, setRestaurantInfo] = useState(""); | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| return ( | ||||||||||||||||||||||||||||||||
| <div className="modal modal--open"> | ||||||||||||||||||||||||||||||||
| <div className="modal-backdrop" onClick={() => setIsAddModalOpen(false)}></div> | ||||||||||||||||||||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍👍 |
||||||||||||||||||||||||||||||||
|
|
@@ -33,7 +27,9 @@ function AddRestaurantModal({ setIsAddModalOpen }) { | |||||||||||||||||||||||||||||||
| name="category" | ||||||||||||||||||||||||||||||||
| id="category" | ||||||||||||||||||||||||||||||||
| required | ||||||||||||||||||||||||||||||||
| onChange={(selected) => setSelectedCategory(selected.target.value)} | ||||||||||||||||||||||||||||||||
| onChange={(event) => | ||||||||||||||||||||||||||||||||
| setNewRestaurant({ ...newRestaurant, category: event.target.value }) | ||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||
| > | ||||||||||||||||||||||||||||||||
| <option value="">선택해 주세요</option> | ||||||||||||||||||||||||||||||||
| {CATEGORY_DATA.slice(1).map((category) => ( | ||||||||||||||||||||||||||||||||
|
|
@@ -49,7 +45,7 @@ function AddRestaurantModal({ setIsAddModalOpen }) { | |||||||||||||||||||||||||||||||
| name="name" | ||||||||||||||||||||||||||||||||
| id="name" | ||||||||||||||||||||||||||||||||
| required | ||||||||||||||||||||||||||||||||
| onChange={(input) => setRestaurantName(input.target.value)} | ||||||||||||||||||||||||||||||||
| onChange={(event) => setNewRestaurant({ ...newRestaurant, name: event.target.value })} | ||||||||||||||||||||||||||||||||
| /> | ||||||||||||||||||||||||||||||||
| </div> | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
|
|
@@ -60,7 +56,10 @@ function AddRestaurantModal({ setIsAddModalOpen }) { | |||||||||||||||||||||||||||||||
| id="description" | ||||||||||||||||||||||||||||||||
| cols="30" | ||||||||||||||||||||||||||||||||
| rows="5" | ||||||||||||||||||||||||||||||||
| onChange={(input) => setRestaurantInfo(input.target.value)} | ||||||||||||||||||||||||||||||||
| value={newRestaurant.description} | ||||||||||||||||||||||||||||||||
| onChange={(event) => | ||||||||||||||||||||||||||||||||
| setNewRestaurant({ ...newRestaurant, description: event.target.value }) | ||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||
| ></textarea> | ||||||||||||||||||||||||||||||||
|
Comment on lines
+58
to
+63
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
React에 의해 제어되도록 제어 컴포넌트를 사용하시기로 결정하셨다면, 이 요소의
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 오호... 리액트에서 상태는 생각보다 엄청 중요한 개념이네요.
명심하겠습니다!! |
||||||||||||||||||||||||||||||||
| <span className="help-text text-caption">메뉴 등 추가 정보를 입력해 주세요.</span> | ||||||||||||||||||||||||||||||||
| </div> | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,7 +11,7 @@ function CategoryFilter({ category, onChangeCategory }) { | |
| className="restaurant-filter" | ||
| aria-label="음식점 카테고리 필터" | ||
| value={category} | ||
| onChange={() => onChangeCategory(event.target.value)} | ||
| onChange={(event) => onChangeCategory(event.target.value)} | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🔨 ✅ 👍🏻 |
||
| > | ||
| {CATEGORY_DATA.map((category) => ( | ||
| <option key={category}>{category}</option> | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,19 +9,28 @@ const CATEGORY_IN_ENGLISH = Object.freeze({ | |
| 기타: "etc", | ||
| }); | ||
|
|
||
| function RestaurantList({ restaurants, SetIsModalOpen, setRestaurantName, setRestaurantInfo }) { | ||
| const handleClick = (restaurant) => { | ||
| SetIsModalOpen(true); | ||
| setRestaurantName(restaurant.name); | ||
| setRestaurantInfo(restaurant.description); | ||
| function RestaurantList({ restaurants, setModal, modal }) { | ||
| const handleRestaurantClick = (restaurant) => { | ||
| setModal({ | ||
| ...modal, | ||
| isOpen: true, | ||
| restaurant: { | ||
| name: restaurant.name, | ||
| description: restaurant.description, | ||
| }, | ||
| }); | ||
|
Comment on lines
+13
to
+21
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 오, 관심사가 비슷하다고 생각하신 건가요? 이번에 state를 묶어주셨군요 😄 |
||
| }; | ||
|
|
||
| return ( | ||
| <> | ||
| <section className="restaurant-list-container"> | ||
| <ul className="restaurant-list"> | ||
| {restaurants.map((restaurant) => ( | ||
| <li key={restaurant.id} className="restaurant" onClick={() => handleClick(restaurant)}> | ||
| <li | ||
| key={restaurant.id} | ||
| className="restaurant" | ||
| onClick={() => handleRestaurantClick(restaurant)} | ||
| > | ||
| <div className="restaurant__category"> | ||
| <img | ||
| src={`../../templates/category-${CATEGORY_IN_ENGLISH[restaurant.category]}.png`} | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
인터뷰 🎤
제어 컴포넌트(controlled component)와 비제어 컴포넌트(uncontrolled component)란 무엇인가요? 각 방법에서 부각되는 특징은 무엇이라고 생각하시나요?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
제어 컴포넌트(controlled component)
입력값이 상태에 의해 제어되는 컴포넌트입니다. input, textarea 등 입력 필드의 값이 바뀔 때마다 업데이트됩니다.
비제어 컴포넌트(uncontrolled component)
입력값이 상태에 의해 제어되지 않고 입력 필드가 값을 관리하는 컴포넌트 입니다. useRef를 사용해 필요할 때 입력값을 가져옵니다.
각 방법에서 부각되는 특징은 상태가 연결됐는지(컴포넌트와 입력값의 동기화) 여부라고 생각합니다!