목록React.js 엑셀 다운로드 (1)
너와 나의 프로그래밍

API를 호출해서 Blob 타입의 Response 값을 받을 때 다운로드 기능을 구현하는 과정을 설명하려고 한다. 예를들어 "엑셀" 다운로드를 할 때 서버에서 만들어진 Excel을 클라이언트단에서 즉시 다운로드 기능을 구현하려면 아래와 같이 작업하면 된다. // API를 호출하는 코드 const getExcel = useCallback(async () => { try { const blob: Blob = await api.getExcel(); // 타입 명시 const url = window.URL.createObjectURL(blob); const link = document.createElement("a"); link.href = url; link.setAttribute("download", "mem..
Front-End/Next.js & React.js
2023. 5. 7. 22:32