Viewing Existing Destinations
This guide demonstrates rendering existing destinations for your users to inspect.
Step 1: Creating a getDestinations
function
getDestinations
functionIn your frontend, call the useGetDestinationsForRecipient
hook to generate a function that fetches a scoped auth token and uses it to get destinations for the recipient scoped by the token. Leverage one of the fetchToken
functions you wrote in Building an "Add Destination" Connection Form here to create one.
const getDestinations = useGetDestinationsForRecipient(
fetchTokenRecipient, // fetchToken implementation, takes a recipient ID
"app.example.co", // the origin of your React app (used to allow CORS),
PREQUEL_HOST // Optional (default api.prequel.co): the host url of your Prequel API
);
Step 2: Using getDestinations
getDestinations
Use getDestinations
created in Step 1 to fetch destinations for the given recipient.
// Local state to store existing destinations
const [destinations, setDestinations] = useState<ExistingDestination[]>();
// Async function fetches existing destinations from Prequel API
const fetchDestinations = async (id: string) => {
const destinationsResponse = await getDestinations(id);
setDestinations(destinationsResponse.data?.destinations);
};
useEffect(() => {
fetchDestinations(recipientID); // Fetch the destinations for active user's recipient
}, [recipientID]);
Step 3: Rendering destinations
destinations
Render the destinations
fetched from the Prequel API for inspection.
const RecipientDestinations = () => {
// Recipient fetching elided
return (
<>
{destinations.map((d) => (
<div key={d.id}>
<p>{d.id}</p>
<p>{d.name}</p>
<p>{d.vendor}</p>
// ...other destination fields
</div>
))}
</>
);
}
Updated 7 months ago
What’s Next
To learn how add support for users to inspect transfers, see the next tutorial.