Search code examples
linked-datasolid

solid/react-components: useLDflex() for address


I'm trying to read a user's address from their profile with useLDflex() or useLDflexValue().

When I run this:

const address = useLDflex(`[${webId}].vcard_hasAddress`)?.toString() || 'loading...';
console.log('address: ', address);

Console shows:

address:  https://<username>.solidcommunity.net/profile/card#id1234567890,false,

I can go to the URL in my browser and is shows the address object but how do I directly access the contents of the address object in my code? I presume there is a function to resolve the address URL and return the contents but can't find it.

Thank you. Any links to reading material on this topic would also be appreciated.


Solution

  • The vcard:hasAddress predicate of a Solid Profile points to an address resource that then has further properties like vcard:country-name and vcard:locality.

    With ldflex you are able to use a dot notation to "chain" your query. So this will get you the address locality:

    [${webId}].vcard_hasAddress.vcard_locality
    

    Instead of dot notation you can also access the properties with square brackets. This will also work with properties, that contain dashes, like country-name:

    [${webId}].vcard_hasAddress['vcard:country-name']
    

    Give it a try on the LDFlex playground with my WebID.

    If the address is stored in a different document you need to first query the address and then do another query for the address properties:

    1. [${webId}].vcard_hasAddress
    2. [${address}].vcard_locality