I have a problem linking between front & backend , at the backend i have the csv file ready to be downloaded with nomation & 2 parameters of start_date & end_date . `
import fileSaver from 'file-saver';
import {useaApi} from './Api';
import {ApiScope} from './const.api'
interface Props{
start_date: Date;
end_date: Date;
}
export const useCsvDownloader = () => {
const { loading, error, exec } = useApi(ApiScope.scope, ApiScope.api);
const getCsvFile = async ({ start_date, end_date }: Props) => {
const options = {
url:`${API_URL}/csvdownload/?start=${start_date.toISOString()}&end=${end_date.toISOString()}`,
method: 'POST',
data: Request,
responseType: 'blob',
headers: {
'content-type': 'text/csv',
},
};
try {
(response: { data: BlobPart }) => {
fileSaver.saveAs(new Blob([response.data]), __filename);
return true;
};
} catch (error) {
(function (error: any) {
console.error('Failed ', error);
console.error('Failed ', error);
console.log('Failed ', error);
});
}
const data = await exec(options);
return {
data,
};
};
return {
loading,
error,
getCsvFile,
};
};
`
i tried implementing this function but the page don't load up , i expect to download the file directly , is there any method ? any solution ?