React 강석준 sprint6#80
Merged
kiJu2 merged 19 commits intocodeit-bootcamp-frontend:React-강석준from Mar 13, 2025
Hidden character warning
The head ref may contain hidden characters: "React-\uac15\uc11d\uc900-sprint6"
Merged
Conversation
Collaborator
|
스프리트 미션 하시느라 수고 많으셨어요. |
kiJu2
approved these changes
Mar 13, 2025
Comment on lines
+26
to
+27
| # Environment variables | ||
| .env No newline at end of file |
Collaborator
There was a problem hiding this comment.
굿굿 ! 환경 변수를 추가하고 gitignore에 추가하셨군요 ! 👍
Comment on lines
+19
to
+28
| <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 />} /> |
Collaborator
There was a problem hiding this comment.
우와.. 활용도가 너무 좋으신데요?
라이브러리를 정말 잘 사용하시는군요 ! 👍👍👍
Comment on lines
+30
to
+34
| export const postItem = async (item) => { | ||
| const response = await instance.post(PRODUCT_ENDPOINT, item); | ||
| const data = response.data; | ||
| return data; | ||
| }; |
Collaborator
There was a problem hiding this comment.
(선택/소소한 팁..?) 별 건 아니지만..!
Suggested change
| 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 표현식입니다.
Comment on lines
+3
to
+47
| 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; |
Collaborator
There was a problem hiding this comment.
(심화/의견/제안) Label과 Input을 분리해볼 수 있습니다 !:
현재 Label과 Input이 붙어있어요. 분리하면 더욱 활용도가 좋아질 수 있을 것 같아요 !:
Suggested change
| 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" |
Collaborator
There was a problem hiding this comment.
오호 ~ 버튼은 항상 타입을 명시해주시는군요 ? 👍👍
Collaborator
|
수고하셨습니다 석준님 ! 미션 수행하시느라 정말 수고 많으셨습니다 석준님 !! 💪💪 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
요구사항
기본
심화
주요 변경사항
스크린샷
멘토에게