react/src/hooks/useMetadata/README.md

33 lines
851 B
Markdown
Raw Permalink Normal View History

2020-05-19 18:26:26 +02:00
# `useMetadata`
Get metadata for a specific data asset.
2020-08-19 17:03:57 +02:00
`useMetadata` has 3 uses:
2020-09-07 16:32:49 +02:00
- `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
2020-08-19 17:03:57 +02:00
2020-05-19 18:26:26 +02:00
## Usage
```tsx
import React from 'react'
import { useMetadata } from '@oceanprotocol/react'
const did = 'did:op:0x000000000'
export default function MyComponent() {
// Get metadata for this asset
2020-09-07 16:32:49 +02:00
const { title, metadata, price } = useMetadata(did)
2020-05-19 18:26:26 +02:00
const { main, additionalInformation } = metadata
return (
<div>
<h1>{title}</h1>
2020-09-07 16:32:49 +02:00
<p>Price: {price}</p>
2020-05-19 18:26:26 +02:00
</div>
)
}
```