Skip to content

Commit 7d6a16f

Browse files
committed
Additional react docs
1 parent 1dc7fe1 commit 7d6a16f

File tree

1 file changed

+88
-1
lines changed

1 file changed

+88
-1
lines changed

packages/react/README.md

Lines changed: 88 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ A collection of React hooks for implementing web3-onboard in to a React project
66

77
`npm i @web3-onboard/react`
88

9-
## Usage
9+
## Example Usage
1010

1111
```javascript
1212
import React from 'react'
@@ -142,3 +142,90 @@ function App() {
142142

143143
export default App
144144
```
145+
146+
## `init`
147+
148+
The `init` function must be called before any hooks can be used. The `init` function just initializes `web3-onboard` and makes it available for all hooks to use. For reference check out the [initialization docs for `@web3-onboard/core`](../core/README.md#initialization)
149+
150+
## `useConnectWallet`
151+
152+
This hook allows you to connect the user's wallet and track the state of the connection status and the wallet that is connected.
153+
154+
```typescript
155+
import { useConnectWallet } from '@web3-onboard/react'
156+
157+
type UseConnectWallet = (): [
158+
{ wallet: WalletState | null; connecting: boolean },
159+
(options: ConnectOptions) => Promise<void>
160+
]
161+
162+
type ConnectOptions = {
163+
autoSelect?: string // wallet name to autoselect for user
164+
}
165+
166+
type WalletState = {
167+
label: string
168+
icon: string
169+
provider: EIP1193Provider
170+
accounts: Account[]
171+
chains: ConnectedChain[]
172+
instance?: unknown
173+
}
174+
175+
const [
176+
{
177+
wallet, // the wallet that has been connected or null if not yet connected
178+
connecting // boolean indicating if connection is in progress
179+
},
180+
connect // function to call to initiate user to connect wallet
181+
] = useConnectWallet()
182+
```
183+
184+
## `useSetChain`
185+
186+
This hook allows you to set the chain of a user's connected wallet, keep track of the current chain the user is connected to and the status of setting the chain.
187+
188+
```typescript
189+
import { useSetChain } from '@web3-onboard/react'
190+
191+
type UseSetChain = (
192+
walletLabel?: string
193+
): [
194+
{
195+
chains: Chain[]
196+
connectedChain: ConnectedChain | null
197+
settingChain: boolean
198+
},
199+
(options: SetChainOptions) => Promise<void>
200+
]
201+
202+
type SetChainOptions = {
203+
chainId: string
204+
chainNamespace?: string
205+
wallet?: WalletState['label']
206+
}
207+
208+
const [
209+
{
210+
chains, // the list of chains that web3-onboard was initialized with
211+
connectedChain, // the current chain the user's wallet is connected to
212+
settingChain // boolean indicating if the chain is in the process of being set
213+
},
214+
setChain // function to call to initiate user to switch chains in their wallet
215+
] = useSetChain()
216+
```
217+
218+
## `useWallets`
219+
220+
This hook allows you to track the state of all the currently connected wallets.
221+
222+
```typescript
223+
import { useWallets } from '@web3-onboard/react'
224+
225+
type UseWallets = (): WalletState[]
226+
227+
const [
228+
wallets, //
229+
setChain // function to call to initiate user to switch chains in their wallet
230+
] = useSetChain()
231+
```

0 commit comments

Comments
 (0)