NextJS head section contains the HubSpot form script

I'm attempting to insert this script into the Head section of my NextJS project:

<script>
  hbspt.forms.create({
    region: "na1",
    portalId: "XXXXXX",
    formId: "XXXXXX"
});
</script>

However, I encounter two errors:

Error 1: Unexpected token. Did you mean {'}'} or &rbrace;?ts(1381) (pertaining to closing brackets)

Error 2: Syntax error: Unexpected token, expected "}" (in the line "region: "na1")

This snippet is from the indes.jsx file:

import Head from "next/head";
import styled from "styled-components";
import HeroSection from "../components/sections/HeroSection";
import OverviewSection from "../components/sections/OverviewSection";

const Wrapper = styled.div`
  margin-top: 10rem;
`;

export default function HomePage() {
  return (
    <Wrapper>
      <Head>
        <title>Code Shape - Home</title>
        <link rel="icon" href="/favicon.ico" />
        <script
          type="text/javascript"
          id="hs-script-loader"
          async
          defer
          src="//js.hs-scripts.com/8205013.js"
        ></script>
        <script
          charset="utf-8"
          type="text/javascript"
          src="//js.hsforms.net/forms/shell.js"
        ></script>
        <script>
          hbspt.forms.create(
          {
            region: "na1",
            portalId: "XXXXXX",
            formId: "XXXXXX",
          }
          );
        </script>
      </Head>
      <HeroSection />
    </Wrapper>
  );
}

The script is sourced from HubSpot during form generation, so it should be correctly formatted.

Answer №1

The code is in need of escaping, consider enclosing it within the dangerouslySetInnerHTML attribute:

  <Head>
    <script dangerouslySetInnerHTML={{ __html: `
       hbspt.forms.create({
           region: "na1",
           portalId: "XXXXXX",
           formId: "XXXXXX"
       });
     `}} />
  </Head>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

The functionality of mouse hover in multimaterial three.js appears to be not functioning

I'm facing an issue where I want to create a mouse hover effect on an object with multiple materials. See an example here function update() { // Finding intersections // Creating a Ray with the origin at the mouse position // and dire ...

Using Three.JS 'OrbitControls' in VueJS application results in a black screen appearing?

Currently, I've been delving into the basic cube exercise on Three.js, and incorporating the three.js cube into my Vue.JS application. Initially, everything was functioning smoothly, with my cube rotating as intended using animate, etc. However, thi ...

The moment a connection is established, the link abruptly vanishes - NodeJS and MYSQL

Lately, I've been facing a persistent issue with my node application that suddenly started crashing every time a connection is established. This problem emerged out of nowhere after my application had been running smoothly for months. The crash occurr ...

What is the best method to transfer information between main.js and a specific directory?

Is there a way to efficiently pass data between the main and directory components? I would like to automatically activate the directive when main.js loads. Directive code: angular.module('dmv.shared.components'). directive('doImportPackag ...

Unable to transfer specified row data from material-ui datagrid to a function

When attempting to update the user's status or role using datagrid mui and saving the changes with the save button, the id is successfully passed, but the values for the status and role fields are being passed as undefined. What mistake am I making? ...

"Cross-origin resource sharing problem while working with NodeJs, Express, and React on

Currently, I am working on a small project where I am using NodeJs and Express for the backend and React for the client side. In order to tackle CORS policy issues, I have implemented the "cors" npm package on the server side, but unfortunately, it doesn& ...

The function .click does not function properly when used with an anchor element within a figure tag

In my JavaScript-loaded figure, there is an image description and two buttons. Sometimes the description contains a link with a fig attribute, like this: <a fig="allow" href="#tt5">[1]</a> If the anchor is not in a figure and has a fig attrib ...

HashRouter prevents the Framer Motion exit animation from functioning properly

Unfortunately, the exact same question was posted here. Despite no answers provided, I will share my problem as well: Originally, I was using BrowserRouter for routing, but faced issues with refreshing, so I switched to a simple solution using HashRouter ...

Generating a JSON object using HTML select elements

Looking to generate a JSON string that includes select values and inner HTML values in a map format. For example: <select id="my-select"> <option value="1">one</option> <option value="2">two</option> </select> var json ...

Guidelines for passing input values from a custom directive using $resource in Angular

I have been researching how to use ngModel within a custom directive, and while I grasp the concept, I am struggling with implementing it when using $resource. Currently, I am successfully injecting the "file" scope into my directive and making the API ca ...

Sending an array containing a mix of data types from PHP to a JavaScript array

I am facing a problem with my asynchronous / getJSON implementation. I have an array loaded from a MySQL database in a PHP file called "loadblocks.php" and I have verified that the output is correct by echoing json_encode($content). The data is being print ...

Finding the initial visible iFrame in a browser window and displaying its content

It's quite a strange situation... This issue only pertains to IE8 and older versions. So, there's this iFrame that's popping up (and I have no way to control or assign an ID to it), thank you Telerik! // The only way to target it would be: ...

Checkbox does not trigger onCheck event

I am facing an issue with a checkbox component from material-ui where the onCheck event is not firing. <Checkbox label="label" onCheck={onCheck} checked={currentDocument.ispublic} /> function onCheck() { currentDocument.ispublic = !current ...

Updating the JWT token in Angular 6 and making a new request with the updated token

When my JWT authentication token expires (verified by the backend), I need to call a refresh token API and resend the last failed request due to the expired token. I have an Interceptor in place, but I must update the authentication header before sending ...

Question about jQuery's XHR

Currently working on a basic jQuery script to parse JSON data and format it. However, I keep encountering an error in Chrome that says: Resource interpreted as Script but transferred with MIME type text/html. After researching on SO, it seems to be a comm ...

JavaScript conversion of arrays to JSON data structures

Here is the code snippet along with the variable 'polygon': var directionsDisplay; var directionsService = new google.maps.DirectionsService(); var map; var bermudaTriangle; var directionsPoints; var example; var rez; function initialize() { ...

The scroll-to-top arrow remains concealed when the height of the html and body elements is set to 100

I recently added a scroll-to-top arrow using Jquery, and it's functioning flawlessly. However, I encountered an issue when I set body and html to a height of 100%, as it mysteriously disappears. View this fiddle for reference The HTML structure is a ...

Having trouble receiving values sent through AJAX POST requests to PHP

Can anyone help me figure out why my AJAX POST method is not sending the specific section of my URL string to my PHP file? I've checked everything and can't seem to find where the issue lies. When I var_dump the POST variable in my PHP file, it s ...

Verify if the nested arrays within the object consist of any empty elements

Take a look at the object below: { "params": { "time_to_diagnosis": [ { "field": "date_of_diagnosis", "value": "" }, { "field": "date_of_symptom_onset", "value": "2019-09-01" } ], "time ...

Having trouble with less.modifyVars not functioning properly in Visual Studio?

I attempted to dynamically change the LESS variable using HTML within an AngularJS function. The code worked fine on XAMPP with simple HTML and CSS, but when I transferred it to an enterprise app in Visual Studio, it stopped functioning properly. While the ...