-
Notifications
You must be signed in to change notification settings - Fork 10
Conversation
example/src/MetadataExample.tsx
Outdated
const { title, isLoaded, getBestPrice } = useMetadata(did) | ||
const [price, setPrice] = useState<string>() | ||
|
||
useEffect(() => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could we not move this into the hook? So that const { bestPrice } = useMetadata(did)
would work?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i'm confused, you say not to move it in the hook but then you want to use it in the hook const { bestPrice } = useMetadata(did)
? or am i understanding it wrong?
I didn't add bestPrice
to reduce number of calls but if i think more, you would use this in an asset details page were you need all the metadata. So i'll add bestPrice
and keep getBestPrice
in case you don't want to load the whole ddo with useMetadata(did)
and you just want to get a price for a data token like const { getBestPrice } = useMetadata() ; const price = getBestPrice(dtAddress)
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 ddo, so you don't have to fetch the ddo once againuseMetadata()
: loads nothing, useful for using functions like getBestPrice or getBestPool (maybe more in the future) with minimal calls
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah sorry, confusing wording indeed, I meant to move it into the hook and if there is any reason not to do it. So your change is perfect :-)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
and your 3 uses explanation list here is super useful, we should add this to the readme in https://github.com/oceanprotocol/react/tree/main/src/hooks/useMetadata so it doesn't get lost
No description provided.