Skip to content

React library for building apps connected with Tonhub

Notifications You must be signed in to change notification settings

tonwhales/react-ton-x

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

react-ton-x

npm version npm dependencies

Installation

yarn add react-ton-x

Usage

Wrap your root component with TonhubConnectProvider

import { RemoteConnectPersistance, TonhubConnectProvider } from 'react-ton-x';

const App = () => {
    // use any persistent state you want for remote connector
    const [connectionState, setConnectionState] = useLocalStorage<RemoteConnectPersistance>('connection', { type: 'initing' });

    return (
        <TonhubConnectProvider
            network="mainnet"
            url="YOUR APP URL"
            name="YOUR APP NAME"
            debug={false}
            connectionState={connectionState}
            setConnectionState={setConnectionState}
        >
            {/* here goes your applicaton */}
        </TonhubConnectProvider>
    )
}

When use hook in any child component:

import { useTonhubConnect } from 'react-ton-x';

const Page = () => {
    const connect = useTonhubConnect();
    if (connect.state.type === 'initing') {
        return <span>Waiting for session</span>;
    }
    if (connect.state.type === 'pending') {
        return <a href={connect.state.link}>Authorize</a>;
    }
    return (
        <>
            <span>Network: {config.network}</span>
            <span>Address: {config.address.toFriendly()}</span>
        </>
    )
}

About

React library for building apps connected with Tonhub

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published