4
4
46kvolamak2021-08-02 12:34:04
React
46kvolamak, 2021-08-02 12:34:04

How to execute a certain function and after its execution trigger a click on a link?

I have the functionality of downloading a pdf file through the react-pdf library. It is
necessary that everything that is in the test function work first and only then it downloads the pdf file from the link.
How can this be implemented?

<Button href={instance.url} download="test.pdf" color='primary' block outline className='mb-75' disabled={pdfCheck} onClick = {() => test()}>
   Скачать
 </Button>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander, 2021-08-14
@Azurre

For example, you can move the download to a function:

const element = document.createElement('a');
element.href = instance.url;
element.setAttribute('download',  'test.pdf');
element.style.display = 'none';
document.body.appendChild(element);
element.click();
document.body.removeChild(element);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question