-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
EPAM\Sanket_Joshi
committed
Sep 25, 2024
1 parent
e4a75ab
commit 17b8840
Showing
3 changed files
with
37 additions
and
7 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 |
---|---|---|
@@ -1,3 +1,15 @@ | ||
export const useFileDownload = () => { | ||
import { useCallback } from "react" | ||
|
||
export const useFileDownload = (url: string): [() => void] => { | ||
const downloadFile = useCallback(async () => { | ||
const fileUrl = url; | ||
const a = document.createElement("a"); | ||
a.href = fileUrl; | ||
a.download = "Sanket_FE_JS.pdf"; // Optional, set a custom file name | ||
document.body.appendChild(a); | ||
a.click(); | ||
document.body.removeChild(a); | ||
}, [url]) | ||
|
||
return [downloadFile]; | ||
} |
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