@ez-digital/react-hubspot-hook-form
TypeScript icon, indicating that this package has built-in type declarations

1.4.3 • Public • Published

HubSpot Form Component

License Issues RELEASES TypeScript LINKEDIN

This package provides a React component to integrate and customize HubSpot forms seamlessly. It leverages react-hook-form for form handling and validation, allowing you to easily include HubSpot forms in your React applications.

Features

  • Fetches and displays HubSpot forms dynamically based on form ID.
  • Customizable form and field styles.
  • Client-side validation with react-hook-form.
  • Handles form submission with HubSpot API integration.
  • Displays success and error messages.

Installation

To install the package, use npm or yarn:

npm install react-hubspot-hook-form

or

yarn add react-hubspot-hook-form

Pure ESM package

This package is pure ESM. It cannot be require()'d from CommonJS.

Usage

It's crucial to keep your PORTAL_ID and HUBSPOT_API_TOKEN secure to prevent unauthorized form submissions and other actions. To achieve this, set up your own server to store these environment variables and handle form requests. Remember, HubSpot mandates that form data requests be submitted from a server, rejecting any client-side requests.

React Example Next.js Example

How to Obtain a HubSpot API Token

To obtain your HubSpot API token, please visit this link.

Props

The HubSpotForm component accepts the following props:

Here's the updated table and corresponding documentation:

Table

Prop Type Default Description
fieldGroups FieldGroup[] Required An array of field groups to be displayed in the form.
submitButtonText string Required The text to display on the submit button.
onSubmit SubmitHandler<T> Required The form submit handler function.
isLoading boolean false Indicates if the form is currently loading data.
isSubmitting boolean false Indicates if the form is currently being submitted.
isSubmitted boolean false Indicates if the form has been successfully submitted.
loader ReactNode Custom loader Custom loader component to display while fetching form data.
skeletonHeight number | string 400 Height of the skeleton loader.
successMessage string "The form has been submitted successfully." Message displayed upon successful form submission.
errorMessage string undefined Message displayed upon form submission error.
formStyles React.CSSProperties {} Custom styles for the form container.
formClassName string "" Custom class name for the form container.
fieldGroupStyles React.CSSProperties {} Custom styles for the field groups.
fieldGroupClassName string "" Custom class name for the field groups.
fieldControlStyles React.CSSProperties {} Custom styles for the field controls.
fieldControlClassName string "" Custom class name for the field controls.
labelStyles React.CSSProperties {} Custom styles for the labels.
labelClassName string "" Custom class name for the labels.
fieldStyles React.CSSProperties {} Custom styles for the input fields.
fieldClassName string "" Custom class name for the input fields.
successMessageStyles React.CSSProperties {} Custom styles for the success message.
successMessageClassName string "" Custom class name for the success message.
errorMessageStyles React.CSSProperties {} Custom styles for the error message.
errorMessageClassName string "" Custom class name for the error message.
buttonStyles React.CSSProperties {} Custom styles for the submit button.
buttonClassName string "" Custom class name for the submit button.

Customization

You can customize the appearance and behavior of the form by passing custom styles and class names for various parts of the form. Additionally, you can provide custom loader components, success messages, and error messages to match the look and feel of your application. Use the provided styles from @ez-digital/react-hubspot-hook-form/style or style the form by yourself.

Example

Here is a more detailed example demonstrating customization:

import React from "react";
import ReactDOM from "react-dom";

import HubSpotForm from "@ez-digital/react-hubspot-hook-form";
import "@ez-digital/react-hubspot-hook-form/style";

const customStyles = {
  formStyles: { padding: "20px", backgroundColor: "#f9f9f9" },
  fieldGroupStyles: { marginBottom: "15px" },
  labelStyles: { fontWeight: "bold" },
  fieldStyles: { padding: "10px", borderRadius: "4px" },
  buttonStyles: { backgroundColor: "#007bff", color: "#fff" },
};

const App = () => {
  return (
    <HubSpotForm
      successMessage="Thank you for your submission!"
      errorMessage="Please correct the errors and try again."
      formStyles={customStyles.formStyles}
      fieldGroupStyles={customStyles.fieldGroupStyles}
      labelStyles={customStyles.labelStyles}
      fieldStyles={customStyles.fieldStyles}
      buttonStyles={customStyles.buttonStyles}
    />
  );
};

ReactDOM.render(<App />, document.getElementById("root"));

TypeScript

The module is written in TypeScript and type definitions are included.

Contributing

Contributions, issues and feature requests are welcome!

Show your support

Give a ⭐️ if you like this project!

License

This package is licensed under the MIT License. See the LICENSE file for more information.

Package Sidebar

Install

npm i @ez-digital/react-hubspot-hook-form

Weekly Downloads

29

Version

1.4.3

License

MIT

Unpacked Size

24.6 kB

Total Files

6

Last publish

Collaborators

  • eduardko2001
  • geochanto