This is a React hook to query the latest version of a user’s entity record from the store.
const record = useFindEntityRecord(entity);
useFindEntityRecord()
Call useFindEntityRecord
at the top level of your component to find an entity record.
function Profile({entity}) {
const entityRecord = useFindEntityRecord(entity);
if (!entityRecord) {
return <NotFound />;
}
return <div>Name:{entityRecord.content.profile.name}</div>;
}
entity
string
This hook return an EntityRecord
, or undefined
if the record could not be found.
When fetching records, their respective authors’ Entity records are included in the response by default. They are then available in the store to display alongside the records themselves.
In this example we display the name of a Post record’s author right above its content.
function Post({postRecord}) {
const {entity} = postRecord.author;
const authorRecord = useFindEntityRecord(entity);
if (!authorRecord) {
throw new Error("Entity record not found.");
}
return (
<div>
<div>{authorRecord.content.profile.name}</div>
<div>{postRecord.content.text}</div>
</div>
);
}