Skip to content

useNft() 0.6: better caching, Node.js & non-React compatibility ๐Ÿข ๐Ÿš€

Compare
Choose a tag to compare
@bpierre bpierre released this 27 Apr 16:46
· 84 commits to main since this release

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)