React SDK

ProxyStore

Wrap children in a different BAQ scope.

<ProxyStore entity="...">
  ...
</ProxyStore>

Set the BAQ scope for all components inside. This is useful when displaying data from proxied queries.

Props

  • entity string

    • Entity of the proxied user.

Notes

  • If the entity of the authenticated user is provided, this resets the scope to main store.

When dealing with proxied records, we want the data access hooks like useRecordByKey­ to search within the scope of the proxied entity. Here, we want to display a Post record that may be from a proxied query (e.g. when listing posts from another user).

import {
  ProxyStore,
  useRecordByKey,
  useFindEntityRecord,
} from "./baq/store.js";

function Post({proxyEntity, postKey}) {
  return (
    <ProxyStore entity={proxyEntity}>
      <PostContent postKey={postKey} />
    </ProxyStore>
  );
}

function PostContent({postKey}) {
  // These hooks will look into the correct scope
  // if needed to find the requested data.
  const post = useRecordByKey(postKey);
  const author = useFindEntityRecord(post.author.entity);

  return (
    <div>
      <div>From: {author.content.profile.name}</div>
      <div>{post.content.text}</div>
    </div>
  );
}
© 2024 Quentez