react/src/hooks/useMetadata
mihaisc bf3528754a
optimize (#186)
Signed-off-by: mihaisc <mihai.scarlat@smartcontrol.ro>
2020-11-19 12:07:19 +02:00
..
Pool.ts BestPrice updates 2020-10-08 13:02:32 +02:00
README.md useMetadata docs updates 2020-09-07 16:32:49 +02:00
index.ts BestPrice updates 2020-10-08 13:02:32 +02:00
useMetadata.ts optimize (#186) 2020-11-19 12:07:19 +02:00

README.md

useMetadata

Get metadata for a specific data asset.

useMetadata has 3 uses:

  • useMetadata(did) : it gets the DDO and then loads all the values (title, metadata etc)
  • useMetadata(ddo) : it uses the passed DDO and the loads all the values, in case you already got a list of DDOs, so you don't have to fetch the DDO once again
  • useMetadata() : loads nothing, useful for using functions like getPrice or getPool with minimal calls

Usage

import React from 'react'
import { useMetadata } from '@oceanprotocol/react'

const did = 'did:op:0x000000000'

export default function MyComponent() {
  // Get metadata for this asset
  const { title, metadata, price } = useMetadata(did)

  const { main, additionalInformation } = metadata

  return (
    <div>
      <h1>{title}</h1>
      <p>Price: {price}</p>
    </div>
  )
}