<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: HELP: Embed a form in a React component in APIs &amp; Integrations</title>
    <link>https://community.hubspot.com/t5/APIs-Integrations/HELP-Embed-a-form-in-a-React-component/m-p/674379#M55432</link>
    <description>&lt;P&gt;hello there, there a simple and better way to do that, just install via npm this package&lt;/P&gt;&lt;P&gt;&lt;A href="https://www.npmjs.com/package/react-hubspot-form" target="_blank"&gt;https://www.npmjs.com/package/react-hubspot-form&lt;/A&gt;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt; import HubspotForm from 'react-hubspot-form'


&amp;lt;HubspotForm
                portalId='22384747'
                formId='556eed30-2d51-4224-86f8-ffa83f0bde15'
                onSubmit={() =&amp;gt; console.log('Submit!')}
                onReady={(form) =&amp;gt; console.log('Form ready!')}
                loading={&amp;lt;div&amp;gt;Loading...&amp;lt;/div&amp;gt;}
            /&amp;gt;&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;that work for me and was so easy, also i recomend remove strict mode from your index, i got a problem with that i dont know why but my form was rendering twice, i just removed that and that way i fixed the form, if have question reply &lt;span class="lia-unicode-emoji" title=":grinning_face_with_big_eyes:"&gt;😃&lt;/span&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 02 Aug 2022 18:03:45 GMT</pubDate>
    <dc:creator>DGomez2</dc:creator>
    <dc:date>2022-08-02T18:03:45Z</dc:date>
    <item>
      <title>HELP: Embed a form in a React component</title>
      <link>https://community.hubspot.com/t5/APIs-Integrations/HELP-Embed-a-form-in-a-React-component/m-p/230042#M8938</link>
      <description>&lt;P&gt;Hi all,&lt;/P&gt;
&lt;P&gt;I’m having trouble embedding a hubspot form into a React component. JSX will consider the script tag as a React component itself and try to compile it as such. Have you guys tried to integrate a hubspot form with react before?&lt;/P&gt;
&lt;P&gt;Any help would be appreciated! thanks!&lt;/P&gt;
&lt;P&gt;fabrice&lt;/P&gt;</description>
      <pubDate>Thu, 28 Jul 2016 00:48:07 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/APIs-Integrations/HELP-Embed-a-form-in-a-React-component/m-p/230042#M8938</guid>
      <dc:creator>fabrice</dc:creator>
      <dc:date>2016-07-28T00:48:07Z</dc:date>
    </item>
    <item>
      <title>Re: HELP: Embed a form in a React component</title>
      <link>https://community.hubspot.com/t5/APIs-Integrations/HELP-Embed-a-form-in-a-React-component/m-p/230043#M8939</link>
      <description>&lt;P&gt;Did you ever solve this problem? I’m encountering the same issue now and don’t know how to fix it…&lt;/P&gt;</description>
      <pubDate>Wed, 12 Oct 2016 20:39:52 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/APIs-Integrations/HELP-Embed-a-form-in-a-React-component/m-p/230043#M8939</guid>
      <dc:creator>Alena</dc:creator>
      <dc:date>2016-10-12T20:39:52Z</dc:date>
    </item>
    <item>
      <title>Re: HELP: Embed a form in a React component</title>
      <link>https://community.hubspot.com/t5/APIs-Integrations/HELP-Embed-a-form-in-a-React-component/m-p/230044#M8940</link>
      <description>&lt;P&gt;&lt;A class="mention" href="https://community.hubspot.com/u/alena"&gt;@Alena&lt;/A&gt; and &lt;A class="mention" href="https://community.hubspot.com/u/fabrice"&gt;@fabrice&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;I just spun something up really quickly.  Here is my code so I hope this helps. You can’t unfortunately use script tags in a render function as noted above.  Let me know if this solves your problem or not. The first part calls the HubSpot script from our servers and the second part will then use the contents of said script to place the form in your component.  I had to use a later lifecylce stage to get it to work.  I was hoping it would have worked with componentDidMount(){} but it seemed to be firing to fast before the WillMount() could full finish loading the script.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE&gt;export default class Foo extends Component {
componentWillMount(){

const script = document.createElement("script");


    script.src = "https://js.hsforms.net/forms/v2.js";
    script.async = true;

document.body.appendChild(script);


  }
  componentDidUpdate(){
    //you will need to change the below to match your portal ID and your form ID
     hbspt.forms.create({ 
     portalId: '2323210',
     formId: 'd8232cf6-b9ed-4abc-a81e-585801849cea'
   });
  }
  render() {
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;…Your Render code below&lt;/P&gt;</description>
      <pubDate>Wed, 12 Oct 2016 22:04:27 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/APIs-Integrations/HELP-Embed-a-form-in-a-React-component/m-p/230044#M8940</guid>
      <dc:creator>3PETE</dc:creator>
      <dc:date>2016-10-12T22:04:27Z</dc:date>
    </item>
    <item>
      <title>Re: HELP: Embed a form in a React component</title>
      <link>https://community.hubspot.com/t5/APIs-Integrations/HELP-Embed-a-form-in-a-React-component/m-p/230045#M8941</link>
      <description>&lt;P&gt;Hi &lt;A class="mention" href="https://community.hubspot.com/u/pmanca"&gt;@pmanca&lt;/A&gt; !&lt;/P&gt;
&lt;P&gt;Thanks for that. I implemented it as per your instructions but unfortunately that still doesn’t work. It throws the error that hbspt doesn’t exist, when this runs as the library is probably not fully loaded yet when I’m calling the forms.create function.&lt;/P&gt;
&lt;P&gt;I’ve solved it by hardcoding the first script part where the library is loaded onto my root HTML (in Rails) and then moving the function call into the componentDidMount.&lt;/P&gt;
&lt;P&gt;Works for me although it feels dirty… &lt;IMG src="https://community.hubspot.com/legacyfs/online/emojis/twitter/smiley.png?v=5" title=":smiley:" class="emoji" alt=":smiley:" /&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 13 Oct 2016 20:47:31 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/APIs-Integrations/HELP-Embed-a-form-in-a-React-component/m-p/230045#M8941</guid>
      <dc:creator>Alena</dc:creator>
      <dc:date>2016-10-13T20:47:31Z</dc:date>
    </item>
    <item>
      <title>Re: HELP: Embed a form in a React component</title>
      <link>https://community.hubspot.com/t5/APIs-Integrations/HELP-Embed-a-form-in-a-React-component/m-p/230046#M8942</link>
      <description>&lt;P&gt;Still not working, I’m hacking it as &lt;A class="mention" href="https://community.hubspot.com/u/alena"&gt;@Alena&lt;/A&gt; did but it is really gross. Can you please provide a solution for this?  Thanks&lt;/P&gt;</description>
      <pubDate>Fri, 27 Jan 2017 02:55:30 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/APIs-Integrations/HELP-Embed-a-form-in-a-React-component/m-p/230046#M8942</guid>
      <dc:creator>fabrice</dc:creator>
      <dc:date>2017-01-27T02:55:30Z</dc:date>
    </item>
    <item>
      <title>Re: HELP: Embed a form in a React component</title>
      <link>https://community.hubspot.com/t5/APIs-Integrations/HELP-Embed-a-form-in-a-React-component/m-p/230047#M8943</link>
      <description>&lt;P&gt;Since we’re dealing with iframes anyway, I created another iframe pointing to a route that only had the hubspot div and script.&lt;/P&gt;
&lt;P&gt;/contact&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class="lang-auto"&gt;&amp;lt;iframe className="meetings-wrapper" src="/meetings"&amp;gt;&amp;lt;/iframe&amp;gt;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;/meetings&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class="lang-auto"&gt;&amp;lt;html&amp;gt;
  &amp;lt;body&amp;gt;
    &amp;lt;div style="max-width: 500px;" class="meetings-iframe-container" data-src="https://app.hubspot.com/meetings/youruser?embed=true"&amp;gt;&amp;lt;/div&amp;gt;
    &amp;lt;script type="text/javascript" src="https://static.hsappstatic.net/MeetingsEmbed/ex/MeetingsEmbedCode.js"&amp;gt;&amp;lt;/script&amp;gt;
  &amp;lt;/body&amp;gt;
&amp;lt;/html&amp;gt;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 02 Apr 2017 12:54:01 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/APIs-Integrations/HELP-Embed-a-form-in-a-React-component/m-p/230047#M8943</guid>
      <dc:creator>CaseyBinkley</dc:creator>
      <dc:date>2017-04-02T12:54:01Z</dc:date>
    </item>
    <item>
      <title>Re: HELP: Embed a form in a React component</title>
      <link>https://community.hubspot.com/t5/APIs-Integrations/HELP-Embed-a-form-in-a-React-component/m-p/230048#M8944</link>
      <description>&lt;P&gt;I am new to react …but How should we use the render function in that case?&lt;BR /&gt;
Basically what should be inserted in the render method so that it get the information from the  componentDidUpdate method?&lt;/P&gt;</description>
      <pubDate>Fri, 11 Aug 2017 20:52:52 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/APIs-Integrations/HELP-Embed-a-form-in-a-React-component/m-p/230048#M8944</guid>
      <dc:creator />
      <dc:date>2017-08-11T20:52:52Z</dc:date>
    </item>
    <item>
      <title>Re: HELP: Embed a form in a React component</title>
      <link>https://community.hubspot.com/t5/APIs-Integrations/HELP-Embed-a-form-in-a-React-component/m-p/316107#M30250</link>
      <description>&lt;P&gt;Aweome, this definitely helped me! Thanks. I used useEffect instead of&amp;nbsp;componentDidMount, with success.&lt;/P&gt;</description>
      <pubDate>Fri, 31 Jan 2020 19:17:11 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/APIs-Integrations/HELP-Embed-a-form-in-a-React-component/m-p/316107#M30250</guid>
      <dc:creator>aalstes</dc:creator>
      <dc:date>2020-01-31T19:17:11Z</dc:date>
    </item>
    <item>
      <title>Re: HELP: Embed a form in a React component</title>
      <link>https://community.hubspot.com/t5/APIs-Integrations/HELP-Embed-a-form-in-a-React-component/m-p/520436#M48362</link>
      <description>&lt;P&gt;This is great. Worked perfectly for us right away. Thank you!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is a typescript friendly version (really just supressing the warnings) that uses a functional component and useEffect instead of class component and componentDidMount.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;import React, {useEffect} from "react";

const HubspotContactForm = () =&amp;gt; {
    useEffect(() =&amp;gt; {
        const script = document.createElement('script');
        script.src='https://js.hsforms.net/forms/v2.js';
        document.body.appendChild(script);

        script.addEventListener('load', () =&amp;gt; {
            // &lt;a href="https://community.hubspot.com/t5/user/viewprofilepage/user-id/5004"&gt;@TS&lt;/a&gt;-ignore
            if (window.hbspt) {
                // &lt;a href="https://community.hubspot.com/t5/user/viewprofilepage/user-id/5004"&gt;@TS&lt;/a&gt;-ignore
                window.hbspt.forms.create({
                    portalId: 'YOUR_PORTAL_ID_HERE',
                    formId: 'YOUR_FORM_ID_HERE',
                    target: '#hubspotForm'
                })
            }
        });
    }, []);

    return (
        &amp;lt;div&amp;gt;
            &amp;lt;div id="hubspotForm"&amp;gt;&amp;lt;/div&amp;gt;
        &amp;lt;/div&amp;gt;
    );

}

export default HubspotContactForm;&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 03 Nov 2021 17:41:37 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/APIs-Integrations/HELP-Embed-a-form-in-a-React-component/m-p/520436#M48362</guid>
      <dc:creator>DHawkings</dc:creator>
      <dc:date>2021-11-03T17:41:37Z</dc:date>
    </item>
    <item>
      <title>Re: HELP: Embed a form in a React component</title>
      <link>https://community.hubspot.com/t5/APIs-Integrations/HELP-Embed-a-form-in-a-React-component/m-p/639181#M53597</link>
      <description>&lt;P&gt;I took a different (slightly more complicated) approach but ended up a functioning form. I just added the base script to a Helmet&amp;nbsp; tag and added the window.hbspt parameter for useEffect.&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;const hubspotForm = () =&amp;gt; {
useEffect(() =&amp;gt; {
    if (window.hbspt) {
      window.hbspt.forms.create({
        portalId: "YOUR-PORTAL-ID",
        formId: "YOUR-FORM-ID",
        target: "YOUR-FORM-CONTAINER-ID"
      });
    }
  },[window.hbspt])
return (
&amp;lt;&amp;gt;
&amp;lt;Helmet&amp;gt;
  &amp;lt;script charset="utf-8" type="text/javascript" src="//js.hsforms.net/forms/v2.js"&amp;gt; &amp;lt;/script&amp;gt;
&amp;lt;/Helmet&amp;gt;
&amp;lt;/&amp;gt;
)
}&lt;/LI-CODE&gt;&lt;P&gt;It's working for me just fine but I'm still a react noob so let me know if it doesn't work for y'all.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 25 May 2022 21:34:57 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/APIs-Integrations/HELP-Embed-a-form-in-a-React-component/m-p/639181#M53597</guid>
      <dc:creator>EdCupaioli</dc:creator>
      <dc:date>2022-05-25T21:34:57Z</dc:date>
    </item>
    <item>
      <title>Re: HELP: Embed a form in a React component</title>
      <link>https://community.hubspot.com/t5/APIs-Integrations/HELP-Embed-a-form-in-a-React-component/m-p/639230#M53603</link>
      <description>&lt;P&gt;Thanks for adding your solution,&amp;nbsp;&lt;a href="https://community.hubspot.com/t5/user/viewprofilepage/user-id/391779"&gt;@EdCupaioli&lt;/a&gt;&amp;nbsp;&lt;span class="lia-unicode-emoji" title=":raising_hands:"&gt;🙌&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;— Jaycee&lt;/P&gt;</description>
      <pubDate>Wed, 25 May 2022 23:49:45 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/APIs-Integrations/HELP-Embed-a-form-in-a-React-component/m-p/639230#M53603</guid>
      <dc:creator>Jaycee_Lewis</dc:creator>
      <dc:date>2022-05-25T23:49:45Z</dc:date>
    </item>
    <item>
      <title>Re: HELP: Embed a form in a React component</title>
      <link>https://community.hubspot.com/t5/APIs-Integrations/HELP-Embed-a-form-in-a-React-component/m-p/674379#M55432</link>
      <description>&lt;P&gt;hello there, there a simple and better way to do that, just install via npm this package&lt;/P&gt;&lt;P&gt;&lt;A href="https://www.npmjs.com/package/react-hubspot-form" target="_blank"&gt;https://www.npmjs.com/package/react-hubspot-form&lt;/A&gt;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt; import HubspotForm from 'react-hubspot-form'


&amp;lt;HubspotForm
                portalId='22384747'
                formId='556eed30-2d51-4224-86f8-ffa83f0bde15'
                onSubmit={() =&amp;gt; console.log('Submit!')}
                onReady={(form) =&amp;gt; console.log('Form ready!')}
                loading={&amp;lt;div&amp;gt;Loading...&amp;lt;/div&amp;gt;}
            /&amp;gt;&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;that work for me and was so easy, also i recomend remove strict mode from your index, i got a problem with that i dont know why but my form was rendering twice, i just removed that and that way i fixed the form, if have question reply &lt;span class="lia-unicode-emoji" title=":grinning_face_with_big_eyes:"&gt;😃&lt;/span&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 02 Aug 2022 18:03:45 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/APIs-Integrations/HELP-Embed-a-form-in-a-React-component/m-p/674379#M55432</guid>
      <dc:creator>DGomez2</dc:creator>
      <dc:date>2022-08-02T18:03:45Z</dc:date>
    </item>
    <item>
      <title>Re: HELP: Embed a form in a React component</title>
      <link>https://community.hubspot.com/t5/APIs-Integrations/HELP-Embed-a-form-in-a-React-component/m-p/729843#M59561</link>
      <description>&lt;P&gt;That works perfectly and it submitting, but after refreshing the page, the form doesn't load. Any fix to this? Probably somehow using state?&lt;/P&gt;</description>
      <pubDate>Mon, 12 Dec 2022 19:52:50 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/APIs-Integrations/HELP-Embed-a-form-in-a-React-component/m-p/729843#M59561</guid>
      <dc:creator>PPetkov</dc:creator>
      <dc:date>2022-12-12T19:52:50Z</dc:date>
    </item>
    <item>
      <title>Re: HELP: Embed a form in a React component</title>
      <link>https://community.hubspot.com/t5/APIs-Integrations/HELP-Embed-a-form-in-a-React-component/m-p/743296#M60427</link>
      <description>&lt;P&gt;I try this code in Next.js application, the script gets loaded, hbspt.form.create gets executed but the form doesn't show up, so the target remains unchanged.&lt;BR /&gt;The solution that worked for me was the&amp;nbsp;&lt;A href="https://community.hubspot.com/t5/APIs-Integrations/HELP-Embed-a-form-in-a-React-component/m-p/230049/highlight/true#M8945" target="_blank" rel="noopener"&gt;answer based on class components.&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 18 Jan 2023 14:45:56 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/APIs-Integrations/HELP-Embed-a-form-in-a-React-component/m-p/743296#M60427</guid>
      <dc:creator>ivanakcheurov</dc:creator>
      <dc:date>2023-01-18T14:45:56Z</dc:date>
    </item>
    <item>
      <title>Re: HELP: Embed a form in a React component</title>
      <link>https://community.hubspot.com/t5/APIs-Integrations/HELP-Embed-a-form-in-a-React-component/m-p/867334#M68398</link>
      <description>&lt;P&gt;Here is a Typescript version without warnings suppression:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;import {useEffect} from "react";

const SubscriptionForm = () =&amp;gt; {
    useEffect(() =&amp;gt; {
        const script = document.createElement('script');
        script.src='https://js.hsforms.net/forms/v2.js';
        document.body.appendChild(script);

        script.addEventListener('load', () =&amp;gt; {
            if ((window as any).hbspt) {
                (window as any).hbspt.forms.create({
                    portalId: 'YOUR-PORTAL-ID',
                    formId: 'YOUR-FORM-ID',
                    target: '#hubspotForm'
                })
            }
        });
    }, []);

    return (
        &amp;lt;div&amp;gt;
            &amp;lt;div id="hubspotForm"&amp;gt;&amp;lt;/div&amp;gt;
        &amp;lt;/div&amp;gt;
    );

}

export default SubscriptionForm;&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 19 Oct 2023 19:55:59 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/APIs-Integrations/HELP-Embed-a-form-in-a-React-component/m-p/867334#M68398</guid>
      <dc:creator>SSopin</dc:creator>
      <dc:date>2023-10-19T19:55:59Z</dc:date>
    </item>
  </channel>
</rss>

