useNft() 0.6: better caching, Node.js & non-React compatibility ๐ข ๐
This version brings two new things: a more agressive caching strategy, and the possibility to use the library without React. Big thanks to @gretzke who implemented this feature ๐ โจ
FetchWrapper
FetchWrapper
is a class that can be instanciated, and allows to access the NFT fetching mechanism without using React. It works in Node.js, or any non-React environment. Unlike the useNft()
hook, the fetchNft()
method of a FetchWrapper
instance does not retry, cache, or do anything else than attempting to fetch the NFT data once.
This is how you can use it:
import { FetchWrapper } from "use-nft"
// Pass the fetcher declaration to the FetchWrapper
// and call the fetchNft() method to retrieve the NFT data.
const fetcher = ["ethers", { ethers, provider: ethers.getDefaultProvider() }]
const fetchWrapper = new FetchWrapper(fetcher)
const result = await fetchWrapper.fetchNft(
"0xd07dc4262bcdbf85190c01c996b4c06a461d2430",
"90473"
)
Related pull request
Cache invalidation mechanism
NFT metadata doesnโt change so often, so the cached data doesnโt need to be invalidated every time the browser window gets focused again. This is the default behavior with useSWR() which useNft() uses internally, and it is now disabled.
Related pull request
Other changes
- Remove
Promise.any()
calls (compat with pre ES2021 envs) (#51)