1.2.1 • Published 1 year ago

@zoralabs/nft-hooks v1.2.1

Weekly downloads
-
License
GPL-3.0
Repository
github
Last release
1 year ago

@zoralabs/nft-hooks

Simple React hooks to load Zora NFT data. Includes on-chain data, NFT metadata, and tools for fetching NFT content if needed.

Put together, these power implementations of the zNFT protocol on any website.

This library consists of a data fetch class and associated React hooks to load NFT data is an easy, efficient manner. The API both batches and caches requests, meaning you can use the hooks across a page without needing to worry about significant performance penalties.

👯 See also: @zoralabs/nft-components a complimentary library to this one to render NFT data on a webpage.

Install:

yarn add @zoralabs/nft-hooks

Then you can import and use the hooks in your react application:

import {useZNFT, useNFTMetadata} from "@zoralabs/nft-hooks";

function MyNFT() {
  const {data} = useZNFT("20");
  const {metadata} = useNFTMetadata(data && data.metadataURI);
  
  return (
    <div>
      <h3>{metadata.title}</h3>
      <p>{metadata.description}</p>
      <p>Owned by: {data.owner.id}</p>
    </div>
  );
}

All hooks:

HookUsage
useNFTFetches on-chain NFT data using a configured backend strategy
useNFTQueryQueries for NFTs using a configured backend strategy
useNFTMetadataFetches off-chain metadata (not required for most indexers)
useNFTContentFetches off-chain content (useful for some text content, but less often used)

Configuration:

To set the network configuration, wrap the hooks used with the NFTFetchConfiguration component.

import {Networks, NFTFetchConfiguration, Strategies} from '@zoralabs/nft-hooks';

const zdkStrategy = Strategies.ZDKFetchStrategy();

function NFTGallery() {
  return (
    <NFTFetchConfiguration strategy={zdkStrategy} networkId={Networks.MAINNET}>
      <NFTList>
    </NFTFetchConfiguration>
  );
}

Data sources:

Provided strategies are: 1. ZDKFetchStrategy from the zora indexer (recommended) 2. ZoraV2Indexer strategy from the legacy zora indexer (deprecated) 3. ZoraGraphStrategy strategy from the zora subgraph (not recommended) 4. EtherActorStrategy using ether.actor as a nft backend (not recommended) 5. OpenseaStrategy using opensea's api as a nft backend (not recommended)

Links direct to zora.co interfaces, but can be overridden to directly use the zdk instead.

Development:

  1. git clone https://github.com/ourzora/nft-hooks
  2. cd nft-hooks
  3. npm i -g yarn if you don't have yarn installed
  4. yarn
  5. yarn run test test your code

Pull requests and tickets are accepted for issues and improvements to this library.

1.2.0

1 year ago

1.0.19

2 years ago

1.0.18

2 years ago

1.0.9

2 years ago

1.0.8

2 years ago

1.0.7

2 years ago

1.0.5

2 years ago

1.0.4

2 years ago

1.2.1

1 year ago

1.0.22

2 years ago

1.0.21

2 years ago

1.0.20

2 years ago

1.0.26

2 years ago

1.0.24

2 years ago

1.0.23

2 years ago

1.0.29

2 years ago

1.0.28

2 years ago

1.0.27

2 years ago

1.0.32

2 years ago

1.0.31

2 years ago

1.0.30

2 years ago

1.1.1

2 years ago

1.1.0

2 years ago

1.1.9

2 years ago

1.1.8

2 years ago

1.1.7

2 years ago

1.1.6

2 years ago

1.1.5

2 years ago

1.1.4

2 years ago

1.1.3

2 years ago

1.1.2

2 years ago

1.1.10

2 years ago

1.0.11

2 years ago

1.0.10

2 years ago

0.8.3

2 years ago

1.0.15

2 years ago

1.0.13

2 years ago

1.0.12

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.3

2 years ago

0.7.2

3 years ago

0.7.1

3 years ago

0.7.3

2 years ago

0.7.0

3 years ago

0.8.1

2 years ago

0.8.0

2 years ago

0.8.2

2 years ago

0.5.3

3 years ago

0.5.2

3 years ago

0.6.2

3 years ago

0.6.1

3 years ago

0.6.0

3 years ago

0.5.1

3 years ago

0.5.0

3 years ago

0.4.8

3 years ago

0.5.0-pre1

3 years ago

0.5.0-pre3

3 years ago

0.5.0-pre

3 years ago

0.4.7-pre

3 years ago

0.4.7-pre2

3 years ago

0.4.6-pre

3 years ago

0.4.6

3 years ago

0.4.4-pre2

3 years ago

0.4.4-pre

3 years ago

0.4.5

3 years ago

0.4.3

3 years ago

0.4.2

3 years ago

0.3.0

3 years ago

0.4.1

3 years ago

0.3.2

3 years ago

0.2.3

3 years ago

0.4.0

3 years ago

0.3.1

3 years ago

0.3.3

3 years ago

0.2.2

3 years ago

0.2.1

3 years ago

0.2.0

3 years ago

0.1.9

3 years ago

0.1.8

3 years ago

0.1.7

3 years ago

0.1.6

3 years ago

0.1.5

3 years ago

0.1.4

3 years ago

0.1.3

3 years ago

0.1.2

3 years ago

0.1.1

3 years ago

0.1.0

3 years ago