I have an API that returns a pdf. I need that when I click a button downloads that pdf. I tried it on Postman and it returned the pdf correctly. My current code:
const [document, setDocument] = useState();
const downloadFile = async () => {
const source = axios.CancelToken.source();
setLoading(true);
await getDocument(source); //getDocument saves document on
setLoading(false);
};
const getDocument = useCallback (async (source) => {
await DocumentCalls.getDocument(setDocument, source)
}, []);
And my button:
<Button
onClick={downloadFile}
>
Download File
</Button>