50-fix_multiple_requests_firing_upon_thumbnail_drop #51
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.
Description & Technical Solution
해당 문제는 아래와 같은 상황에서 반복적으로 발생했습니다. (fix_multiple_requests_firing_upon_thumbnail_drop #50)
초기 해결안 : useCallback으로 해당 이미지 컴포넌트를 감싸서, 업로드한 파일 (files)만 변경되었을 경우 함수를 재실행하도록 했습니다.
이로 인해서, 여러번 요청이 발생하는 문제는 해결되었지만, 드랍존은 토글이 가능한 panel 컴포넌트의 일부로, 해당 컴포넌트 토글을 닫았을 경우, 미리보기 이미지가 사라지고, path만 저장되는 문제가 있었습니다.
최종 해결안: 로컬스토리지를 활용하여, dropzone에 이미지를 드랍했을 경우 파일리더를 생성하고, 해당 이미지를 dataurl로 로컬 스토리지와 thumbnail이라는 state에 저장하고, thumbnail와 file을 useCallback의 의존성 배열에 추가하여 변경되었을 경우만 함수가 재실행되도록 했습니다.
Checklist