基础理论反应
薄反射包装 基础理论 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