0.36.1 • Published 9 months ago

@fuels/react v0.36.1

Weekly downloads
-
License
Apache-2.0
Repository
-
Last release
9 months ago

discord

⚡️ Fuel Wallet React Hooks

The Fuel Wallet React Hooks provide a set of hooks to seamless integrate the Fuel Wallet browser extension with any React JS or Next JS project.

Installation

npm install fuels @fuel-wallet/react

Note that the fuels package is also required as a dependency for better integration with other applications built using the Fuels TS SDK.

Usage

Setup the provider

Adding the providers on the upper level of the application that will use the hooks.

import { FuelProvider } from '@fuel-wallet/react';

import { App } from './App';

ReactDOM.createRoot(document.getElementById('root') as HTMLElement).render(
  <React.StrictMode>
    <FuelProvider>
      <App />
    </FuelProvider>
  </React.StrictMode>,
);

Connecting to Wallet

import { useState } from 'react';
import {
  useConnect,
  useConnectors,
  useDisconnect,
  useIsConnected,
} from '@fuel-wallet/react';

export default function App() {
  const [connector, setConnector] = useState('');
  const { connectors } = useConnectors();
  const { connect } = useConnect();
  const { disconnect } = useDisconnect();
  const { isConnected } = useIsConnected();

  return (
    <div
      style={{
        display: 'flex',
        flexDirection: 'column',
        gap: 10,
        padding: 10,
        maxWidth: 300,
      }}
    >
      <select
        onChange={(e) => {
          console.log(e.target.value);
          setConnector(e.target.value);
        }}
      >
        <option value="">Select a connector</option>
        {connectors.map((c) => (
          <option key={c.name} value={c.name}>
            {c.name}
          </option>
        ))}
      </select>
      <button disabled={!connector} onClick={() => connect(connector)}>
        Connect to {connector}
      </button>
      <button disabled={!connector} onClick={() => disconnect()}>
        Disconnect from {connector}
      </button>
      <p>{isConnected ? 'Connected' : ''}</p>
    </div>
  );
}

Please visit our docs to get started using the Fuel Wallet React Hooks.

Additionally, you can check up the Fuel Wallet React Hooks reference for more details.

📜 License

This repo is licensed under the Apache-2.0 license. See LICENSE for more information.

0.36.1

9 months ago

0.36.0

10 months ago

0.36.0-main-57dc2f6

10 months ago

0.35.2-main-9d5e004

10 months ago

0.35.2-main-46000eb

10 months ago

0.35.1-main-d6e12c9

10 months ago

0.32.0-main-9a20224

10 months ago

0.32.0

10 months ago

0.33.0-main-aa757db

10 months ago

0.29.0

10 months ago

0.29.6

10 months ago

0.29.5

10 months ago

0.29.4

10 months ago

0.29.3

10 months ago

0.29.2

10 months ago

0.29.1

10 months ago

0.33.0

10 months ago

0.32.0-main-5a2cfe3

10 months ago

0.31.3-main-1ffb4b5

10 months ago

0.32.1-main-58d0388

10 months ago

0.31.6-main-450b612

10 months ago

0.31.5-main-11f468c

10 months ago

0.30.1

10 months ago

0.30.0

10 months ago

0.31.6

10 months ago

0.31.5

10 months ago

0.31.4

10 months ago

0.31.3

10 months ago

0.31.2

10 months ago

0.31.5-main-64c291f

10 months ago

0.31.1

10 months ago

0.31.0

10 months ago

0.31.5-main-28022d0

10 months ago

0.34.0-main-cdac8d4

10 months ago

0.35.0-main-5c3d337

10 months ago

0.31.1-main-fa88dca

10 months ago

0.31.2-main-d40b0b7

10 months ago

0.30.2-main-296748c

10 months ago

0.34.2-main-9c0923b

10 months ago

0.31.5-main-4eecdf3

10 months ago

0.34.1-main-b0708e3

10 months ago

0.31.4-main-9c1db2e

10 months ago

0.34.2

10 months ago

0.34.1

10 months ago

0.34.0

10 months ago

0.33.1-main-cd36eda

10 months ago

0.35.1

10 months ago

0.35.0

10 months ago

0.31.0-main-4303a90

10 months ago

0.28.1

11 months ago

0.28.0

11 months ago

0.27.1

11 months ago

0.27.0

11 months ago

0.26.0

11 months ago

0.20.0

1 year ago

0.25.0

12 months ago

0.23.0

1 year ago

0.21.0

1 year ago

0.24.0

12 months ago

0.22.0

1 year ago

0.19.0

1 year ago

0.18.1

1 year ago

0.18.0

1 year ago

0.17.0

1 year ago

0.16.0

1 year ago

0.15.3

1 year ago

0.15.2

1 year ago

0.15.1

1 year ago