Pocket & renderer
usePocketCardActions
Presses and value changes inside one Pocket card's face
usePocketCardActions(cardId, onAction) subscribes to the actions triggered
inside one card's face: a clickAction or valueChangeAction named in the
tree the card sent comes back as a PocketCardAction with the actionId and
the payload. It is the only channel back from a face, which is otherwise a
one-way stream. The handler is read through a ref, so it may close over
state freely. Host-only: standalone onError receives HostUnavailableError.
Usage
import { usePocketCardActions } from "@use-truapi/react";
function CardController() {
usePocketCardActions("balance", (action) => {
if (action.actionId === "refresh") refetchBalance();
});
return null;
}<script setup lang="ts">
import { usePocketCardActions } from "@use-truapi/vue";
usePocketCardActions("balance", (action) => {
if (action.actionId === "refresh") refetchBalance();
});
</script>API reference
React
function usePocketCardActions(
cardId,
onAction,
options?): void;Presses and value changes inside one card's face, via a stable handler.
Parameters
| Parameter | Type |
|---|---|
cardId | string | undefined |
onAction | (action) => void |
options? | { enabled?: boolean; onError?: (error) => void; } |
options.enabled? | boolean |
options.onError? | (error) => void |
Returns
void
Vue
function usePocketCardActions(
cardId,
onAction,
options?): void;Presses and value changes inside one card's face.
Parameters
| Parameter | Type |
|---|---|
cardId | MaybeGetter<string | undefined> |
onAction | (action) => void |
options? | { enabled?: MaybeGetter<boolean>; onError?: (error) => void; } |
options.enabled? | MaybeGetter<boolean> |
options.onError? | (error) => void |
Returns
void