-
Notifications
You must be signed in to change notification settings - Fork 1
✨feat: ImageUpload 컴포넌트 구현 #95
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 3 commits
6c23cea
0d8dcfe
9d9ee1d
c95b0a7
0b25aca
b091bc3
ab8a0b8
09ce141
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 | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,72 @@ | ||||||
| import { useEffect, useRef, useState } from 'react'; | ||||||
| import Camera from '@/assets/icons/camera.svg'; | ||||||
|
|
||||||
| interface ImageUploadProps { | ||||||
| label: string; | ||||||
| value: string; | ||||||
| onChange: (file: File, previewUrl: string) => void; | ||||||
| } | ||||||
|
|
||||||
| export default function ImageUpload({ | ||||||
|
||||||
| label, | ||||||
| value, | ||||||
|
||||||
| onChange, | ||||||
| }: ImageUploadProps) { | ||||||
| const fileInputRef = useRef<HTMLInputElement | null>(null); | ||||||
|
||||||
| const [preview, setPreview] = useState<string>(value); | ||||||
|
||||||
| const [preview, setPreview] = useState<string>(value); | |
| const [preview, setPreview] = useState(value); |
💬 자동적으로 type 추론이 되어서 이렇게 적어도 될 것 같습니다!
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.
넵 알겠습니다!
Outdated
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.
💬 버튼이 아니기도 하고 다른 Click Event handler가 없어서 그냥 handleClick으로 이름을 해도 괜찮을 것 같습니다~
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.
넵 좋습니다!
Outdated
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.
❓ 아마 배울 때는 URL.createObjectURL을 사용했던 것 같은데, FileReader를 쓰신 이유가 있으신가요?
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.
아 그렇네요 까먹고 있었습니다! 바꾸도록 하겠습니다!
Outdated
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.
💬 너비를 설정해야 한다면 상위 태그에서 조정하는 것이 맞을 것 같습니다! 그리고 w-full로 두거나 className을 받아서 상위에서 너비를 조절하게 한다면 더 좋을 것 같습니다~
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.
넵 알겠습니다!
Outdated
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을 이미지 미리보기로 많이 활용하는 편입니다! 기본적으로 label과 input을 연결해 주면 label을 눌렀을 때 input을 클릭했을 때와 동일한 동작을 보여서 label로 사용한다면 handleButtonClick 함수가 필요 없을 듯 합니다~
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.
오 좋은 방법이네요 한 번 바꿔보겠습니다!

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.
❓ 어떤 함수인지 잘 모르겠습니다!
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.
이미지를 바꾸는 함수인데 이름이 모호한 것 같네요 변경하겠습니다!