Skip to content

Commit 93fada6

Browse files
committed
fix: image upload twice when uploaed via button
1 parent b8c9914 commit 93fada6

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

src/containers/write/MarkdownEditorContainer.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -234,10 +234,15 @@ const MarkdownEditorContainer: React.FC<MarkdownEditorContainerProps> = () => {
234234
],
235235
);
236236

237+
const postIdRef = useRef(postId);
238+
useEffect(() => {
239+
postIdRef.current = postId;
240+
}, [postId]);
241+
237242
const uploadWithPostId = useCallback(
238243
async (file: File) => {
239244
if (!file) return;
240-
let id = postId;
245+
let id = postIdRef.current;
241246
if (!id) {
242247
const title = titleRef.current || 'Temp Title';
243248
const body = bodyRef.current || 'Temp Body';
@@ -270,7 +275,7 @@ const MarkdownEditorContainer: React.FC<MarkdownEditorContainerProps> = () => {
270275
toast.error('이미지 업로드 실패! 잠시 후 다시 시도하세요.');
271276
});
272277
},
273-
[postId, cfUpload, writePost, dispatch, history],
278+
[cfUpload, writePost, dispatch, history],
274279
);
275280

276281
const onDragDropUpload = useCallback(

src/lib/hooks/useUpload.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ const useUpload = () => {
55
const upload = useCallback(() => {
66
const promise = new Promise<File | null>((resolve, reject) => {
77
const input = document.createElement('input');
8+
input.accept = 'image/*';
89

910
const timeout = setTimeout(reject, 1000 * 60 * 3);
1011
input.type = 'file';

0 commit comments

Comments
 (0)