-
Notifications
You must be signed in to change notification settings - Fork 20
React 강석준 sprint6 #80
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
React 강석준 sprint6 #80
The head ref may contain hidden characters: "React-\uAC15\uC11D\uC900-sprint6"
Conversation
|
스프리트 미션 하시느라 수고 많으셨어요. |
| # Environment variables | ||
| .env |
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.
굿굿 ! 환경 변수를 추가하고 gitignore에 추가하셨군요 ! 👍
| <Route element={<Layout />}> | ||
| <Route path="/" element={<Home />} /> | ||
| <Route path="/items" element={<Items />} /> | ||
| <Route path="/additem" element={<AddItem />} /> | ||
| <Route path="/boards" element={<Boards />} /> | ||
| </Route> | ||
| <Route path="/login" element={<Login />} /> | ||
| <Route path="/signup" element={<Signup />} /> | ||
| <Route path="/privacy" element={<Policy />} /> | ||
| <Route path="/faq" element={<Faq />} /> |
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.
우와.. 활용도가 너무 좋으신데요?
라이브러리를 정말 잘 사용하시는군요 ! 👍👍👍
| export const postItem = async (item) => { | ||
| const response = await instance.post(PRODUCT_ENDPOINT, item); | ||
| const data = response.data; | ||
| return data; | ||
| }; |
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.
(선택/소소한 팁..?) 별 건 아니지만..!
| export const postItem = async (item) => { | |
| const response = await instance.post(PRODUCT_ENDPOINT, item); | |
| const data = response.data; | |
| return data; | |
| }; | |
| export const postItem = async (item) => { | |
| const { data } = await instance.post(PRODUCT_ENDPOINT, item); | |
| return data; | |
| }; |
위와 같이 구조 분해 할당으로 간략히 작성할 수 있습니다 ! 😊
구조 분해 할당 구문은 배열이나 객체의 속성을 해체하여 그 값을 개별 변수에 담을 수 있게 하는 JavaScript 표현식입니다.
| function AddItemInputField({ | ||
| id, | ||
| name, | ||
| type, | ||
| label, | ||
| placeholder, | ||
| value, | ||
| setValue, | ||
| onEnterKeyDown, | ||
| onBlur, | ||
| }) { | ||
| const handleEnterKeyDown = (e) => { | ||
| if (!onEnterKeyDown) return; | ||
| if (e.key === "Enter") { | ||
| e.preventDefault(); | ||
| onEnterKeyDown(e.target.value); | ||
| setValue(""); | ||
| } | ||
| }; | ||
|
|
||
| return ( | ||
| <div> | ||
| <label htmlFor={id} className="text-lg font-bold text-gray-800"> | ||
| {label} | ||
| </label> | ||
| <div | ||
| className={`mt-4 flex h-14 w-full items-center justify-stretch gap-3 rounded-xl bg-gray-100 px-6`} | ||
| > | ||
| <input | ||
| id={id} | ||
| name={name} | ||
| type={type} | ||
| placeholder={placeholder} | ||
| value={value} | ||
| className={`w-full text-gray-800 placeholder:font-normal placeholder:text-gray-400 focus:outline-none ${type === "number" ? "[appearance:textfield] [&::-webkit-inner-spin-button]:appearance-none [&::-webkit-outer-spin-button]:appearance-none" : ""}`} | ||
| onChange={(e) => setValue(e.target.value)} | ||
| onKeyDown={handleEnterKeyDown} | ||
| onBlur={onBlur} | ||
| /> | ||
| </div> | ||
| </div> | ||
| ); | ||
| } | ||
|
|
||
| export default AddItemInputField; |
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.
(심화/의견/제안) Label과 Input을 분리해볼 수 있습니다 !:
현재 Label과 Input이 붙어있어요. 분리하면 더욱 활용도가 좋아질 수 있을 것 같아요 !:
| function AddItemInputField({ | |
| id, | |
| name, | |
| type, | |
| label, | |
| placeholder, | |
| value, | |
| setValue, | |
| onEnterKeyDown, | |
| onBlur, | |
| }) { | |
| const handleEnterKeyDown = (e) => { | |
| if (!onEnterKeyDown) return; | |
| if (e.key === "Enter") { | |
| e.preventDefault(); | |
| onEnterKeyDown(e.target.value); | |
| setValue(""); | |
| } | |
| }; | |
| return ( | |
| <div> | |
| <label htmlFor={id} className="text-lg font-bold text-gray-800"> | |
| {label} | |
| </label> | |
| <div | |
| className={`mt-4 flex h-14 w-full items-center justify-stretch gap-3 rounded-xl bg-gray-100 px-6`} | |
| > | |
| <input | |
| id={id} | |
| name={name} | |
| type={type} | |
| placeholder={placeholder} | |
| value={value} | |
| className={`w-full text-gray-800 placeholder:font-normal placeholder:text-gray-400 focus:outline-none ${type === "number" ? "[appearance:textfield] [&::-webkit-inner-spin-button]:appearance-none [&::-webkit-outer-spin-button]:appearance-none" : ""}`} | |
| onChange={(e) => setValue(e.target.value)} | |
| onKeyDown={handleEnterKeyDown} | |
| onBlur={onBlur} | |
| /> | |
| </div> | |
| </div> | |
| ); | |
| } | |
| export default AddItemInputField; | |
| function Label({ htmlFor, children }) { | |
| return ( | |
| <label htmlFor={htmlFor} className="text-lg font-bold text-gray-800"> | |
| {children} | |
| </label> | |
| ); | |
| } | |
| function Input({ id, name, type = "text", className, onEnterKeyDown, setValue, ...rest }) { | |
| const handleEnterKeyDown = (e) => { | |
| if (!onEnterKeyDown) return; | |
| if (e.key === "Enter") { | |
| e.preventDefault(); | |
| onEnterKeyDown(e.target.value); | |
| setValue && setValue(""); | |
| } | |
| }; | |
| return ( | |
| <input | |
| id={id} | |
| name={name} | |
| type={type} | |
| className={cn( | |
| "w-full text-gray-800 placeholder:font-normal placeholder:text-gray-400 focus:outline-none", | |
| { | |
| "[appearance:textfield] [&::-webkit-inner-spin-button]:appearance-none [&::-webkit-outer-spin-button]:appearance-none": | |
| type === "number", | |
| }, | |
| className | |
| )} | |
| onKeyDown={handleEnterKeyDown} | |
| {...rest} | |
| /> | |
| ); | |
| } |
이렇게 하면 Label과 Input이 각각 독립적인 컴포넌트가 되어 다른 곳에서도 재사용을 기대해볼 수 있고 각각의 스타일과 속성을 확장할 수 있습니다 !
또한 ...rest로 생략가능한(별도 논리적인 연산이 필요 없는) props들을 생략해볼 수 있어요 !
| <div className="my-6 flex items-center justify-between"> | ||
| <div className="text-xl font-bold text-gray-800">상품 등록하기</div> | ||
| <button | ||
| type="submit" |
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.
오호 ~ 버튼은 항상 타입을 명시해주시는군요 ? 👍👍
|
수고하셨습니다 석준님 ! 미션 수행하시느라 정말 수고 많으셨습니다 석준님 !! 💪💪 |
요구사항
기본
심화
주요 변경사항
스크린샷
멘토에게