I'm trying to load two js scripts in componentdidmount and want a retry logic 4 times.
What would be the best way to handle two scripts in one function?
function loadScript(scriptUrl1, scriptUrl2, retries = 4) {
const getScript= document.createElement("script");
getScript.onerror = () => {
if (retries > 0) {
loadScript(scriptUrl1, scriptUrl2, retries - 1);
} else {
console.log("failed to load")
}
}
script1.src = scriptUrl1;
script2.src = scriptUrl2;
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…