React SDK

useFindEntityRecord

This is a React hook to query the latest version of a user’s entity record from the store.

const record = useFindEntityRecord(entity);

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>;
}

Parameters

  • entity string

    • Entity of the user whose Entity record we want to find.

Returns

This hook return an EntityRecord­, or undefined if the record could not be found.

Notes

  • Always returns the latest version of Entity record available in the store. The hook automatically updates when a new version becomes available.

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>
  );
}
© 2024 Quentez