When user clicks on <a>
, I want to first get a new href
resolved by a promise, and then trigger the change of window location. But I can't find a good practice to do this.
To conclude, here's psuedo code:
getNewUrl = (e) => {
e.preventDefault();
fetchUrl.then(newUrl => {
newUrl = newUrl;
e.resumeEvent();
})
}
<a
href={newUrl}
onClick={this.getNewUrl}
/>
But obviously there's no e.resumeEvent(). What should I do to handle this?
(Don't want to fetch url massively in componentDidMount()
, as there might be many requests)