use-truapi
Pocket & renderer

usePocketCards

The product's cards in the host's Pocket tab, live

usePocketCards returns the cards the host currently holds for this product (Pocket.list_subscribe), as a live list: the whole set on subscribe and again after every change. Each PocketCard carries its cardId and whether it is privileged (placed by the host itself, so the product cannot remove it). The host owns the collection — a product declares its cards in the worker manifest, observes them here and may remove them, but cannot add one.

Host-only: standalone the query errors with HostUnavailableError, so gate it on useIsHost or pass enabled.

Usage

import { useIsHost, usePocketCards } from "@use-truapi/react";

function Cards() {
  const isHost = useIsHost();
  const { data: cards } = usePocketCards({ enabled: isHost });
  if (!isHost) return null;
  return (
    <ul>
      {cards?.map((card) => (
        <li key={card.cardId}>{card.cardId}{card.privileged ? " (host)" : ""}</li>
      ))}
    </ul>
  );
}
<script setup lang="ts">
import { useIsHost, usePocketCards } from "@use-truapi/vue";

const isHost = useIsHost();
const { data: cards } = usePocketCards({ enabled: () => isHost.value });
</script>

<template>
  <ul v-if="isHost">
    <li v-for="card in cards" :key="card.cardId">{{ card.cardId }}{{ card.privileged ? " (host)" : "" }}</li>
  </ul>
</template>

See also

API reference

React

function usePocketCards(options?): UseQueryResult<PocketCard[], Error>;

The product's Pocket cards, live: the whole set on subscribe and again after every change. The host owns the collection — a product observes and removes its cards but cannot add one. Host-only: standalone the query errors with HostUnavailableError.

Parameters

ParameterType
options?{ enabled?: boolean; query?: QueryOptions<PocketCard[]>; }
options.enabled?boolean
options.query?QueryOptions<PocketCard[]>

Returns

UseQueryResult<PocketCard[], Error>

Vue

function usePocketCards(options?): QueryResult<PocketCard[]>;

The product's Pocket cards, live: the whole set on subscribe and again after every change. The host owns the collection — a product observes and removes its cards but cannot add one. Host-only: standalone the query errors with HostUnavailableError.

Parameters

ParameterType
options?{ enabled?: MaybeGetter<boolean>; query?: QueryOptions<PocketCard[]>; }
options.enabled?MaybeGetter<boolean>
options.query?QueryOptions<PocketCard[]>

Returns

QueryResult<PocketCard[]>

On this page