I'm able to get a Hubspot form working as a component in Gatsby, but I would like to be able to set the formId per page. I've tried setting props in my component but haven't been successful. Here is an example of a page with the form working, and the code is below, with my portal id removed.
import React from "react";
class HubspotBrochureDownload extends React.Component {
componentDidMount() {
const script = document.createElement("script");
script.src = "https://js.hsforms.net/forms/v2.js";
document.body.appendChild(script);
script.addEventListener("load", () => {
if (window.hbspt) {
window.hbspt.forms.create({
portalId: "XXXXXX",
formId: "1152aa7a-835d-410d-9462-08e2ddd226d8",
target: "#hubspotForm"
});
}
});
}
render() {
return (
<div>
<div id="hubspotForm"></div>
</div>
);
}
}
export default HubspotBrochureDownload;
I have tried removing my formID and putting props. I found this example of componentDidUpdate but haven't had any luck