Skip to content

Commit aa556f1

Browse files
committed
[Portal] Update docs for useActiveWallet (#4352)
## Problem solved Short description of the bug fixed or feature added <!-- start pr-codex --> --- ## PR-Codex overview The focus of this PR is to enhance the `useActiveWallet` hook by adding examples demonstrating its usage for account and network change events. ### Detailed summary - Added examples for basic usage, account change event, multiple accounts changed event, and network change event in the `useActiveWallet` hook. > ✨ Ask PR-Codex anything about this PR by commenting with `/codex {your question}` <!-- end pr-codex -->
1 parent 3a55a7e commit aa556f1

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

packages/thirdweb/src/react/core/hooks/wallets/useActiveWallet.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,40 @@ import { useConnectionManagerCtx } from "../../providers/connection-manager.js";
55
* A hook that returns the active wallet
66
* @returns The active `Wallet` or `undefined` if no active wallet is set.
77
* @example
8+
*
9+
* ### Basic usage
810
* ```jsx
911
* import { useActiveWallet } from "thirdweb/react";
1012
*
1113
* const wallet = useActiveWallet();
1214
* ```
15+
*
16+
* ### Listen to account change event
17+
* ```jsx
18+
* const wallet = useActiveWallet();
19+
*
20+
* wallet?.subscribe("accountChanged", (account) => {
21+
* console.log(account);
22+
* });
23+
* ```
24+
*
25+
* ### Listen to multiple accounts changed event
26+
* ```jsx
27+
* const wallet = useActiveWallet();
28+
*
29+
* wallet?.subscribe("accountsChanged", (addresses) => {
30+
* console.log(addresses);
31+
* });
32+
* ```
33+
*
34+
* ### Listen to network change event
35+
* ```jsx
36+
* const wallet = useActiveWallet();
37+
*
38+
* wallet?.subscribe("chainChanged", (chain) => {
39+
* console.log(chain);
40+
* });
41+
* ```
1342
* @walletConnection
1443
*/
1544
export function useActiveWallet() {

0 commit comments

Comments
 (0)