I am having a simple react component, the fire is printed once, but injectWindowInterval is called twice event though i am setting flag value, why is it so?
const Header = () => {
  let flag = true;
  
  console.log("fire");  
  function injectWindowInterval() {
    if (flag && window.google) {
      flag = false;
      console.log(window.google);
    }
  }
  const script = document.createElement("script");
  script.src = "https://accounts.google.com/gsi/client";
  script.onload = injectWindowInterval;
  script.async = true;
  document.querySelector("body")?.appendChild(script);
  return (
    <div className="header">
      <h3 className="header__title">RE</h3>
    </div>
  );
};
Update: for some reason, the script is appending twice in body.
 
     
    