@basis-theory/basis-theory-react

中文文档
1.32.5发布于 2025/04/22Apache-2.0TypeScriptESM + CJS近 30 天下载 4.8万

Basic Theory JS SDK的瘦回放包装

中文使用文档
文档目录9 节
  1. 安装
  2. 文档
  3. 使用量
  4. 初始化
  5. 上下文提供者
  6. 要件
  7. 发展
  8. 依赖关系
  9. 构建 SDK 并运行测试

基础理论反应

Version Downloads Verify

薄反射包装 基础理论 JS SDK(英语:JS SDK).

安装

使用 节点软件包管理器

npm install --save @basis-theory/basis-theory-react

使用 雅伦

yarn add @basis-theory/basis-theory-react

文档

关于终点和例子的完整清单,请参见我们 反应文件

使用量

初始化

SDK的初始化是通过调用 useBasisTheory 有参数的钩子 :

import { useBasisTheory } from '@basis-theory/basis-theory-react';

export default function MyWrapper() {
  const { bt, error } = useBasisTheory('<Public API Key>'); // replace with your application key

  // instance stays undefined during initialization
  if (bt) {
    // able to call BasisTheory methods
  }

  if (error) {
    // initialization error
  }
}

上下文提供者

你可以通过 BasisTheoryReact 下到组件树 BasisTheoryProvider,然后访问它以后叫 useBasisTheory 无任何参数的钩子 :

import {
  BasisTheoryProvider,
  useBasisTheory,
} from '@basis-theory/basis-theory-react';

const App = () => {
  const { bt } = useBasisTheory('<Public API Key>', {
    elements: true,
  });

  return (
    <BasisTheoryProvider bt={bt}>
      <MyComponent />
    </BasisTheoryProvider>
  );
};

const MyComponent = () => {
  // calling this hook with no attributes grabs the instance from Context
  const { bt } = useBasisTheory();

  return <div>My content</div>;
};

要件

要件 在通过时具备能力 elements: true 在初始化选项中.

import {
  BasisTheoryProvider,
  TextElement,
  useBasisTheory,
} from '@basis-theory/basis-theory-react';

const App = () => {
  const { bt } = useBasisTheory('<Public API Key>', {
    elements: true,
  });

  return (
    <BasisTheoryProvider bt={bt}>
      <MyComponent />
    </BasisTheoryProvider>
  );
};

const MyComponent = () => {
  // calling this hook with no attributes grabs the instance from Context
  const { bt } = useBasisTheory();

  return <TextElement id="myInput" />;
};

发展

与 SDK 提供的脚本将检查所有依赖,构建解决方案并运行所有测试.

依赖关系

构建 SDK 并运行测试

从工程根部运行以下命令 :

make verify

版本与发布记录

@basis-theory/basis-theory-react 共发布 69 个版本,首次发布于 2021/08/14;过去 12 个月发布了 0 个版本。

版本发布日期距今
1.32.5latest2025/04/221.5 年前
1.32.42025/03/261.6 年前
1.32.32025/03/071.7 年前
1.32.22025/02/221.7 年前
1.32.12025/02/211.7 年前
1.32.02025/02/211.7 年前

其他发布通道:main → 1.0.0-alpha.5,master → 1.0.0-alpha.10。

关于 @basis-theory/basis-theory-react 的常见问题

@basis-theory/basis-theory-react 是什么?

Basic Theory JS SDK的瘦回放包装

如何安装 @basis-theory/basis-theory-react?

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

@basis-theory/basis-theory-react 支持 TypeScript 吗?

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

@basis-theory/basis-theory-react 支持 ESM 还是 CommonJS?

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

@basis-theory/basis-theory-react 需要什么版本的 Node.js?

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

@basis-theory/basis-theory-react 可以商用吗?

@basis-theory/basis-theory-react 使用 Apache-2.0 许可。宽松许可:允许商业使用、修改和再分发,并附带明确的专利授权;分发时需保留许可与 NOTICE 文件,修改过的文件要注明改动。以上为概括,不构成法律意见,请以许可原文为准。

@basis-theory/basis-theory-react 的下载量有多少?

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

@basis-theory/basis-theory-react 还在维护吗?

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