@aaronhayes/react-use-hubspot-form

中文文档
2.1.2发布于 2025/07/15MITTypeScriptESM + CJS零依赖近 30 天下载 5.7万

Embed HubSpot forms into your React components using hooks! Works with Create React App, Gatsby and other platforms.

原始使用文档
文档目录5 节
  1. Install
  2. Getting Started
  3. Usage
  4. Breaking Changes
  5. 2.0.0

React Use HubSpot Form Embed

npm (scoped) Bundle Size License

Embed HubSpot forms into your React components using hooks! Works with Create React App, Gatsby and other platforms.

Install

$ npm install --save @aaronhayes/react-use-hubspot-form
$ yarn add @aaronhayes/react-use-hubspot-form

Getting Started

Wrap your application with HubspotProvider. This will add Hubspot script to the head of your document.

import React from 'react';

import { HubspotProvider } from '@aaronhayes/react-use-hubspot-form';

const MyApp = () => (
    <HubspotProvider>
        <MyPage />
    </HubspotProvider>
)

Usage

import React from 'react';

import { useHubspotForm } from '@aaronhayes/react-use-hubspot-form';

const MyPage = () => {
    const { loaded, error, formCreated } = useHubspotForm({
        portalId: 'XXXXXXX',
        formId: 'XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX',
        target: '#my-hubspot-form'
    });

    return (
        <div>
            <h1>Embed Form Below</h1>
            <div id="my-hubspot-form"></div>
        </div>
    )
}

Breaking Changes

2.0.0

  • Introduction of the HubspotProvider component. This needs to be included in your App for useHubspotForm to work.

版本与发布记录

@aaronhayes/react-use-hubspot-form 共发布 14 个版本,首次发布于 2019/11/23;过去 12 个月发布了 0 个版本。

版本发布日期距今
2.1.2latest2025/07/151.3 年前
2.1.12022/02/054 年前
2.1.02021/09/215 年前
2.0.12021/08/085 年前
1.2.62021/06/245 年前
1.2.52021/04/225 年前

关于 @aaronhayes/react-use-hubspot-form 的常见问题

@aaronhayes/react-use-hubspot-form 是什么?

Embed HubSpot forms into your React components using hooks! Works with Create React App, Gatsby and other platforms.

如何安装 @aaronhayes/react-use-hubspot-form?

在项目目录运行 npm install @aaronhayes/react-use-hubspot-form,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:react(>=16.8.0)、react-dom(>=16.8.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@aaronhayes/react-use-hubspot-form 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@aaronhayes/react-use-hubspot-form 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@aaronhayes/react-use-hubspot-form 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=10.16。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@aaronhayes/react-use-hubspot-form 可以商用吗?

@aaronhayes/react-use-hubspot-form 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@aaronhayes/react-use-hubspot-form 的下载量有多少?

根据 npm 官方下载统计,@aaronhayes/react-use-hubspot-form 在 2026/10/05 – 2026/11/03 这 30 天内被下载 56,642 次,日均约 1,888 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@aaronhayes/react-use-hubspot-form 还在维护吗?

最新版本 2.1.2 发布于 2025/07/15(1.3 年前);至今共发布 14 个版本,其中过去 12 个月发布了 0 个;首次发布于 2019/11/23。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。