Skip to content

Commit 50b1f0a

Browse files
committed
fix(sdk): build suspense into nft provider
1 parent f4eeed3 commit 50b1f0a

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

packages/thirdweb/src/react/web/ui/prebuilt/NFT/provider.tsx

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { createContext, useContext } from "react";
1+
import { Suspense, createContext, useContext } from "react";
22
import type { ThirdwebContract } from "../../../../../contract/contract.js";
33

44
/**
@@ -14,6 +14,10 @@ export type NFTProviderProps = {
1414
* The tokenId whose info you want to display
1515
*/
1616
tokenId: bigint;
17+
/**
18+
* Fallback content to display while the NFT data is being fetched
19+
*/
20+
fallback?: React.ReactNode;
1721
};
1822

1923
/**
@@ -57,19 +61,17 @@ export function useNFTContext() {
5761
* client: yourThirdwebClient,
5862
* });
5963
*
60-
* <NFT.Provider contract={contract} tokenId={0n}>
61-
* <Suspense fallback={"Loading media..."}>
62-
* <NFT.Media />
63-
* <NFT.Description />
64-
* </Suspense>
64+
* <NFT.Provider contract={contract} tokenId={0n} fallback={"Loading media..."}>
65+
* <NFT.Media />
66+
* <NFT.Description />
6567
* </NFT>
6668
* ```
6769
* @nft
6870
*/
6971
export function Provider(props: React.PropsWithChildren<NFTProviderProps>) {
7072
return (
7173
<NFTProviderContext.Provider value={props}>
72-
{props.children}
74+
<Suspense fallback={props.fallback ?? null}>{props.children}</Suspense>
7375
</NFTProviderContext.Provider>
7476
);
7577
}

0 commit comments

Comments
 (0)