I am using a hubspot form in my next.js site - I want to render the form on page load as you can see in the code.
The undesired effect is that the form renders twice, I want to build in a system so it only renders on page load and thats it. How do I achieve this?
I tried to follow this to solve it but did not work https://www.youtube.com/watch?v=KzH6YxW0zW4.
Code below
useEffect(() => {
let isCancelled = false;
const script = document.createElement('script');
script.src = "//js-eu1.hsforms.net/forms/v2.js";
document.body.appendChild(script)
if (!isCancelled) {
script.addEventListener('load', () => {
if (window.hbspt){
hubspotForm();
}
})
}
return () => {
isCancelled = true
};
}, [])