0.0.3 • Published 6 days ago

@tensferhq/react-tensfer v0.0.3

Weekly downloads
-
License
MIT
Repository
-
Last release
6 days ago

useTensfer Hook

The useTensfer hook is a custom React hook designed to integrate with the Tensfer payment service. It allows you to easily manage Tensfer widget initialization and handle its callbacks within your React components.

Installation

To use the useTensfer hook in your React project, you need to install the package:

npm install @tensferhq/react-tensfer

API

The useTensfer Hook takes in an object of the following properties:

  • publicKey (required): Your Tensfer public key gotten from Tensfer Dashboard.
  • payment (optional): An array of objects containing payment options.

and returns an object with the following:

  • error: A string representing any error that occurred during widget initialization.
  • close: A string informing that the widget was closed by the user.
  • data: An object representing the data returned by the Tensfer widget.
  • initWidget: A function to initialize the Tensfer widget.

Example

import React from "react";
import { useTensfer } from "@tensferhq/react-tensfer";


const TensferHookExample = () => {
  const props = {
        publicKey: "YOUR_PUBLIC_KEY",

        payment: [
             {
                type:  // withdrawal or deposit
                address: //wallet address ,
                network: // e.g BNB Smart Chain,
                currency: //currency or token to transfer to
                amount: //amount
            },
        ],
    };

    const { error, close, data, initWidget } = useTensfer(props);

    return (
        <div>
            <button onClick={initWidget}>
                Tensfer Hooks Implementation
            </button>
        </div>
    );
};

function App() {
    return <TensferHookExample />;
}

export default App;