Skip to content

Commit c410a1c

Browse files
authored
[react, react-core] - Migrate Docs content to JSDoc comments (#2084)
1 parent 81c46e2 commit c410a1c

File tree

181 files changed

+7578
-2238
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

181 files changed

+7578
-2238
lines changed

.changeset/bright-impalas-remain.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
---
2+
"@thirdweb-dev/react-native": patch
3+
"@thirdweb-dev/react-core": patch
4+
"@thirdweb-dev/storage": patch
5+
"@thirdweb-dev/wallets": patch
6+
"@thirdweb-dev/chains": patch
7+
"@thirdweb-dev/react": patch
8+
"@thirdweb-dev/sdk": patch
9+
---
10+
11+
JSDoc comments Improvements

packages/chains/src/async.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ export async function fetchChains(options?: {
8383
/**
8484
*
8585
* @param chainId - the chainId of the chain to resolve
86-
* @returns a Promise that resolves to the Chain object
86+
* @returns A Promise that resolves to the Chain object
8787
* @throws if the chainId is not found
8888
*/
8989
export async function getChainByChainIdAsync(chainId: number): Promise<Chain> {
@@ -98,7 +98,7 @@ export async function getChainByChainIdAsync(chainId: number): Promise<Chain> {
9898
/**
9999
*
100100
* @param slug - the slug of the chain to resolve
101-
* @returns a Promise that resolves to the Chain object
101+
* @returns A Promise that resolves to the Chain object
102102
* @throws if the slug is not found
103103
*/
104104
export async function getChainBySlugAsync(slug: string): Promise<Chain> {

packages/react-core/src/core/hooks/useNetwork.ts

Lines changed: 105 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,23 +35,120 @@ type NetworkMetadata = {
3535
* It's important to note that some wallet apps do not support programmatic network switching and switchNetwork will be undefined.
3636
* For those situations, you can typically switch networks in the wallet app this hook will still work.
3737
*
38+
* Hook for getting information about the current network and switching to a different network.
39+
*
40+
* Returns an array value containing two elements.
41+
*
42+
* 1. An object containing the following properties:
43+
*
44+
* - `data` object contains information about the wallet's current and supported networks.
45+
* - `loading` indicates if the switch network request is in progress.
46+
* - `error` holds the `Error` object if there was an error when attempting to switch network.
47+
*
48+
* 2. A function to switch to a different network.
49+
*
3850
* @example
3951
* ```javascript
4052
* import { useNetwork } from "@thirdweb-dev/react";
4153
*
42-
* const App = () => {
43-
* const [, switchNetwork] = useNetwork();
54+
* function App() {
55+
* const [{ data, error, loading }, switchNetwork] = useNetwork();
56+
*
4457
* return (
45-
* // switchNetwork is undefined if the wallet does not support programmatic network switching
46-
* // 137 is the chainId for Polygon in this example
47-
* <button onClick={() => switchNetwork(137)}>
48-
* Switch Network
58+
* <button
59+
* onClick={async () => {
60+
* if (!switchNetwork) {
61+
* console.log("can not switch network");
62+
* return;
63+
* }
64+
*
65+
* const result = await switchNetwork(80001);
66+
* if (result.data) {
67+
* console.log("Switched to Mumbai testnet successfully");
68+
* } else {
69+
* console.log("Error switching to Mumbai testnet", result.error);
70+
* }
71+
* }}
72+
* >
73+
* Switch to Mumbai
4974
* </button>
5075
* );
51-
* };
76+
* }
77+
* ```
78+
*
79+
* @returns
80+
*
81+
* ```ts
82+
* const [{ data, error, loading }, switchNetwork] = useNetwork();
83+
* ```
84+
* #### data
85+
*
86+
* If wallet is connected to a network that is one of `supportedChains` provided in `ThirdwebProvider` or one of the default supported chains, `data` object will contain the following:
87+
*
88+
* ```ts
89+
* {
90+
* chain: Chain; // The connected network
91+
* chains: Chain[]; // All supported networks
92+
* }
93+
* ```
94+
*
95+
* If wallet is connected to a network that is NOT one of `supportedChains` provided in `ThirdwebProvider` or default supported, `data` object will contain the following:
96+
*
97+
* ```ts
98+
* {
99+
* // chainId of current connected network + unsupported flag
100+
* chain: { chainId: number, unsupported: true };
101+
* // All supported networks
102+
* chains: Chain[];
103+
* }
104+
* ```
105+
*
106+
* If wallet is not connected, `data` object will contain the following:
107+
*
108+
* ```ts
109+
* {
110+
* chain: undefined;
111+
* chains: []; // Empty array
112+
* }
113+
* ```
114+
*
115+
* #### error
116+
*
117+
* `error` contains an `Error` object if there was an error when attempting to switch network using the `switchNetwork` function
118+
*
119+
* `undefined` if there is no switch network error
120+
*
121+
* ```ts
122+
* Error | undefined;
123+
* ```
124+
*
125+
* #### loading
126+
*
127+
* `loading` is `true` when switching network using the `switchNetwork` function, and `false` otherwise.
128+
*
129+
*
130+
* #### switchNetwork
131+
*
132+
* `switchNetwork` is a function to switch to a different network. It takes a `chainId` as an argument and returns a promise that resolves to an object containing `data` and `error` properties.
133+
*
134+
* If switching network was successful, `data` will contain the new network information. and `error` will be `undefined`. If switching network failed, `data` will be `undefined` and `error` will contain an `Error` object.
135+
*
136+
* `switchNetwork` is `undefined` if not connected to a wallet or if the connected wallet does not allow programmatic switching.
137+
*
138+
* ```ts
139+
* type SwitchNetwork = undefined | (chainId: number) => Promise<
140+
* | {
141+
* data: Chain | undefined;
142+
* error: undefined;
143+
* }
144+
* | {
145+
* data: undefined;
146+
* error: Error;
147+
* }>
52148
* ```
53149
*
54-
* @deprecated - use `useChain`, `useSwitchChain`, `useChainId` instead
150+
* @deprecated use `useChain`, `useSwitchChain`, `useChainId` instead
151+
* @internal
55152
*/
56153
export function useNetwork(): [NetworkMetadata, SwitchNetwork | undefined] {
57154
const chain = useChain();

0 commit comments

Comments
 (0)