PluginProbe
HubSpot All-In-One Marketing – Forms, Popups, Live Chat / 11.3.69
HubSpot All-In-One Marketing – Forms, Popups, Live Chat v11.3.69
11.3.75 11.3.73 11.3.71 11.3.70 11.3.69 11.3.64 11.3.65 11.3.62 11.3.61 11.3.56 11.3.58 11.0.31 11.0.52 11.0.54 11.0.56 11.0.58 11.0.7 11.1.10 11.1.11 11.1.13 11.1.14 11.1.15 11.1.2 11.1.20 11.1.21 All 73 releases
leadin / scripts / shared / Form / hooks / useFormsScript.ts

useFormsScript.ts in HubSpot All-In-One Marketing – Forms, Popups, Live Chat 11.3.69, at scripts/shared/Form/hooks/useFormsScript.ts

31 lines 666 B
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 import $ from 'jquery';
2
3 import { useEffect, useState } from 'react';
4 import { formsScript } from '../../../constants/leadinConfig';
5 import Raven from '../../../lib/Raven';
6
7 let promise: Promise<string | undefined>;
8
9 function loadFormsScript() {
10 if (!promise) {
11 promise = new Promise((resolve, reject) =>
12 $.getScript(formsScript)
13 .done(resolve)
14 .fail(reject)
15 );
16 }
17 return promise;
18 }
19
20 export default function useFormScript() {
21 const [ready, setReady] = useState(false);
22
23 useEffect(() => {
24 loadFormsScript()
25 .then(() => setReady(true))
26 .catch(error => Raven.captureException(error));
27 }, []);
28
29 return ready;
30 }
31