-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Refactor : 파일 및 파일인풋 훅스 분리 * Refactor : callback 구조 변경 * Refactor : 게시글 삭제 로직 변경 (첨부파일 함께 삭제)
- Loading branch information
1 parent
de1f5dc
commit be8b4c6
Showing
6 changed files
with
120 additions
and
83 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import React, { InputHTMLAttributes } from "react"; | ||
|
||
interface SingleImageInputInterface | ||
extends Omit< | ||
InputHTMLAttributes<HTMLInputElement>, | ||
"onChange" | "type" | "capture" | "style" | "name" | ||
> { | ||
onChange: (file: File) => void; | ||
} | ||
|
||
const SingleImageInput = ({ | ||
onChange, | ||
...others | ||
}: SingleImageInputInterface) => { | ||
return ( | ||
<input | ||
name="image" | ||
style={{ display: "none" }} | ||
type="file" | ||
accept="image/*" | ||
capture="environment" | ||
onChange={(e) => { | ||
if (e.target.files) { | ||
onChange(e.target.files[0]); | ||
} | ||
}} | ||
{...others} | ||
/> | ||
); | ||
}; | ||
|
||
export default SingleImageInput; |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { useEffect, useState } from "react"; | ||
|
||
/** | ||
* file 을 입력받아 dataUrl을 리턴하는 훅 | ||
* @param file | ||
* @returns fileDataUrl | ||
*/ | ||
const useRenderAsDataUrl = (file: File | undefined) => { | ||
const [fileUrl, setFileUrl] = useState<string | ArrayBuffer | null>(null); | ||
|
||
useEffect(() => { | ||
if (!file) { | ||
return; | ||
} | ||
const reader = new FileReader(); | ||
reader.readAsDataURL(file); | ||
reader.onloadend = () => setFileUrl(reader.result); | ||
}, [file]); | ||
|
||
return fileUrl; | ||
}; | ||
|
||
export default useRenderAsDataUrl; |