useNFTMetadata
Hook to fetch NFT Metadata information
type useNFTMetadataType = {
error?: string; // Error: can be thrown from invalid json, unparsable json, network request failure, network request timeout
loading?: boolean; // Easy indicator to determine if the NFT metadata is loading. Same as (!metadata && !error).
metadata?: any; // Raw, validated zora metadata. A error will be thrown if the metadata does not validate.
};import { useNFTMetadata } from "@zoralabs/nft-hooks";
const MediaDataDisplay = ({ uri: string }) => {
const { error, metadata } = useNFTMetadata(uri);
if (metadata) {
if (metadata.version === "catalog-20210202") {
return (
<div>
<h2>
Song: {metadata.body.title} Artist: {metadata.body.artist}
</h2>
{metadata.body.notes && <p>{metadata.body.notes}</p>}
</div>
);
}
// If not a catalog NFT, can render the metadata title and description fields
// from the first zNFT metadata standard.
return (
<div>
<h2>{metadata.title}</h2>
<p>{metadata.description}</p>
</div>
);
}
if (error) {
return <div>Error loading metadata</div>;
}
return <div>metadata loading...</div>;
};Last updated
Was this helpful?