ReservoirKit Hooks
ReservoirKit comes with powerful hooks to make accessing Reservoir data simple and efficient.
Prerequisites ⚙️
Install and configure ReservoirKit
SWR powered hooks
These hooks use SWR, a performant lightweight data fetching hook library. Using SWR means that we can cache requests, batch requests and use powerful features developed and tested by the SWR team. You can utilize hooks across your components without worrying about performance or duplicate network requests. You can also pass in SWR configuration options to each SWR powered hook. Below are the properties returned in each SWR powered hook.
response: The response returned from the api
data: The data extracted from the response
mutate: SWR's mutate function for refreshing data.
error: An api error
isValidating: If there's an ongoing request or revalidation
Infinite Loading Hooks
The following hooks are built with infinite loading in mind. They expose a some useful methods and properties to build an infinite loading UX, in addition to the properties returned by all SWR infinite powered hooks.
hasNextPage: If there is more data to load
isFetchingInitialData: If the initial data has been fetched or not
isFetchingPage: If data is currently being fetched
fetchNextPage: A method to fetch the next page, takes no parameters.
resetCache: A method to clear the SWR cache, resets the page to 0. Calling fetchNextPage will behave like the first time the hook was called
https://swr.vercel.app/docs/pagination#return-values
useTokens
useListings
useOwnerListings
useBids
useUserTopBids
useCollectionActivity
useUsersActivity
useUserCollections
useUserTokens
useTokenActivity
Utility Hooks
Just like every good tool belt there are usually some utility hooks included. These hooks don't necessarily fetch Reservoir data but they are quite useful.
useReservoirClient
useTokenOpenseaBanned
Manually overriding chain endpoint
The hooks above fetch data from the default chain configured in the ReservoirKitProvider
, read more on that here. You can also manually override the chainId for all of these hooks to fetch specific data. Please note that the manually overridden chain needs to be in the list of chains passed to the provider.
Updated almost 2 years ago