The Prequel React SDK provides a comprehensive set of React Hooks to help you embed the functionality of Prequel into your React app.

Available Hooks

HookShapeUsage
useDestinationuseDestination(defaultSettings: Partial<Destination>): [Destination, SetDestinationFunction]Initialize a Destination object and a setDestination function to pass to useDestinationForm and collect data from your user.
useDestinationFormuseDestinationForm(destination, orgIdInPrequel): FormGet a form object that you can render to collect connection information. The form changes based on fields set on the destination.
useModelsuseModels(fetchToken, origin): ModelConfig[]Get all of your Prequel models.
useCreateDestinationuseCreateDestination(fetchToken, origin): CreateDestinationFunctionGenerate a function you can use to submit a completed destination and begin syncing data to your customer.
useTestConnectionuseTestConnection(fetchToken, origin): TestConnectionFunctionGenerate a function you can use to embed a connection test (i.e., to test the destination setup before submitting the destination) into your application.
useUpdateDestinationuseUpdateDestination(fetchToken, origin): UpdateDestinationFunctionGenerate a function you can use to submit changes to an existing destination.
useDeleteDestinationuseDeleteDestination(fetchToken, origin): DeleteDestinationFunctionGenerate a function you can use to delete existing destinations.
useGetTransfersuseProducts(fetchToken, origin): GetTransfersFunctionGenerate a function you can use to get transfers for an existing destination
useGetDestinationsForRecipientuseGetDestinationsForRecipient(fetchToken, origin): GetDestinationsForRecipientFunctionGenerate a function you can use to get destinations for the specified recipient.

Hook usage examples

useDestination

This hook provides a destination object and a function for updating values on that destination. Usage is very similar to that of React's useState hook.

Parameters

NameTypeNotes
initialStatePartial<Destination>Optional. Defaults to predetermined values.

Return Values

ValueType
[destination, setDestination][Destination, SetDestinationFunction]

Example

import { useDestination } from "@prequel/react";

const [destination, setDestination] = useDestination({ name: "Example Destination" });
console.log("Destination Name:", destination.name); // "Example Destination"

setDestination((currentDestination) => ({ ...currentDestination, name: "Updated Destination Name" }));
console.log("Destination Name:", destination.name); // "Updated Destination Name"

useDestinationForm

This hook provides a form object that changes dynamically based on fields set on the given destination.

Parameters

NameTypeNotes
destinationDestinationRequired. The form updates dynamically based on changes to this object.
orgIdstringRequired. The Prequel UUID representing your organization.
includeInternalFieldsbooleanOptional. Default false. Setting to true will include form fields like name and recipient_id that you likely want to set yourself rather than exposing to the user.
hoststringOptional. Defaults to Prequel's US API. Update this if you are running a self-hosted deployment or you are registered with Prequel in another region.

Return Values

ValueType
formForm.

Example

import { useDestination, useDestinationForm } from "@prequel/react";

const [destination, setDestination] = useDestination();
const destinationForm = useDestinationForm(
  destination,
  "your-prequel-org-uuid",
);

return (
  <div>
  {destinationForm.map((section) => (
    // Render the section...
    {section.fields((field) => (
      // Render the field...
    )}
  ))}
  </div>
);

useModels

This hook returns a list of all your models. This hook is most commonly used to add model selection to your destination form.

Parameters

NameTypeNotes
fetchTokenFetchAuthTokenRequired.
originstringRequired. The origin of your React app using the hooks.
hoststringOptional. Defaults to Prequel's US API. Update this if you are running a self-hosted deployment or you are registered with Prequel in another region.

Return Values

ValueType
modelConfigsModelConfig[] | undefined.

Example

import { useModels } from "@prequel/react";

const models = useModels(
  fetchToken,
  "app.example.co",
  PREQUEL_HOST
);

useCreateDestination

This hook generates a function that you can use to create a destination. This function is most commonly used in the submit functionality of your destination form.

Parameters

NameTypeNotes
fetchTokenFetchAuthTokenWithDestinationRequired. Consumes a PreparedDestination and generates a scoped auth token.
originstringRequired. The origin of your React app using the hooks.
hoststringOptional. Defaults to Prequel's US API. Update this if you are running a self-hosted deployment or you are registered with Prequel in another region.

Return Values

ValueType
createDestination(d: PreparedDestination) => Promise<APIResponse<CreateOrUpdateDestinationResponse>>.

Example

import { useCreateDestination, prepareDestinationWithForm } from "@prequel/react";

const createDestination = useCreateDestination(
  fetchToken,
  "app.example.co",
  PREQUEL_HOST
);

// prepareDestinationWithForm usage elided...

async function onFormSubmit() {
  const response = await createDestination(preparedDestination);
  if (response.status === "success") {
    // handle creation success
  } else {
    // handle creation failure
  }
}

useTestConnection

This hook generates a function that you can use to test a destination connection. This function is most commonly used to test new destinations in your form.

Parameters

NameTypeNotes
fetchTokenFetchAuthTokenWithDestinationRequired. Consumes a PreparedDestination and generates a scoped auth token.
originstringRequired. The origin of your React app using the hooks.
hoststringOptional. Defaults to Prequel's US API. Update this if you are running a self-hosted deployment or you are registered with Prequel in another region.

Return Values

ValueType
testConnection(d: PreparedDestination) => Promise<APIResponse<{ status: string }>>.

Example

import { useTestConnection } from "@prequel/react";

const testConnection = useTestConnection(
  fetchToken,
  "app.example.co",
  PREQUEL_HOST
);

async function testDestinationConnection() {
  const { data, status, message } = await testConnection(preparedDestination);
  if (response.status === "success") {
    // handle test success
  } else {
    // handle test failure
  }
}

useUpdateDestination

This hook generates a function that you can use to update a destination.

Parameters

NameTypeNotes
fetchTokenFetchAuthTokenWithExistingDestinationRequired. Consumes an ExistingDestination and generates a scoped auth token.
originstringRequired. The origin of your React app using the hooks.
hoststringOptional. Defaults to Prequel's US API. Update this if you are running a self-hosted deployment or you are registered with Prequel in another region.

Return Values

ValueType
updateDestination(destination: ExistingDestination, changed: Partial<PreparedDestination>) => Promise<APIResponse<CreateOrUpdateDestinationResponse>>.

Example

const { useUpdateDestination } from "@prequel/react";

const updateDestination = useUpdateDestination(
  fetchToken,
  "app.example.co",
  PREQUEL_HOST
);

// destination edits and preparation elided...

async function onSubmitUpdate() {
  const response = await updateDestination(existingDestination, editedPreparedDestination);
  if (response.status === "success") {
    // handle update success
  } else {
    // handle update failure
  }
}

useDeleteDestination

This hook generates a function that you can use to delete a destination.

Parameters

NameTypeNotes
fetchTokenFetchAuthTokenWithExistingDestinationRequired. Consumes an ExistingDestination and generates a scoped auth token.
originstringRequired. The origin of your React app using the hooks.
hoststringOptional. Defaults to Prequel's US API. Update this if you are running a self-hosted deployment or you are registered with Prequel in another region.

Return Values

ValueType
deleteDestination(destination: ExistingDestination) => Promise<APIResponse<{}>>.

Example

import { useDeleteDestination } from "@prequel/react";

const deleteDestination = useDeleteDestination(
  fetchToken,
  "app.example.co",
  PREQUEL_HOST
);

async function onSubmitDelete() {
  const response = await deleteDestination(existingDestination);
  if (response.status === "success") {
    // handle update success
  } else {
    // handle update failure
  }
}

useGetDestinationsForRecipient

This hook generates a function that you can use to get destinations for a given recipient.

Parameters

NameTypeNotes
fetchTokenFetchAuthTokenWithRecipientIdRequired. Consumes a recipient ID and generates a scoped auth token.
originstringRequired. The origin of your React app using the hooks.
hoststringOptional. Defaults to Prequel's US API. Update this if you are running a self-hosted deployment or you are registered with Prequel in another region.

Return Values

InputType
getDestinationsForRecipient(recipientId: string) => Promise<APIResponse<GetDestinationsAPIResponse>>.

Example

import { useGetDestinationsForRecipient } from "@prequel/react";

const getDestinationsForRecipient = useGetDestinationsForRecipient(
  fetchToken,
  "app.example.co",
  PREQUEL_HOST
);

const destinations = getDestinationsForRecipient("prequel-recipient-uuid");

useGetTransfers

This hook generates a function you can use to fetch transfers for an ExistingDestination

Parameters

NameTypeNotes
fetchTokenFetchAuthTokenWithExistingDestinationRequired. Consumes an ExistingDestination and generates a scoped auth token.
originstringRequired. The origin of your React app using the hooks.
hoststringOptional. Defaults to Prequel's US API. Update this if you are running a self-hosted deployment or you are registered with Prequel in another region.

Return Values

ValueType
getTransfers(d: ExistingDestination, params?: GetTransfersParams) => Promise<APIResponse<TransfersResponse>>.

Example

import { useGetTransfers, TransferStatus } from "@prequel/react";

// destination fetching elided...

const getTransfers = useGetTransfers(
  fetchToken,
  "app.example.co",
  PREQUEL_HOST
);

// Get all transfers for destination
const allTransfers = getTransfers(destination);

// Get transfers for destination with limit
const someTransfers = getTransfers(destination, { count: 5 });

// Get all transfers for destination with success status
const successfulTransfers = getTransfers(destination, { status: TransferStatus.SUCCESS });

Hooks vs. Components

Prequel provides a comprehensive set of React Hooks to help you embed Prequel's functionality into your app, though there are no pre-built React Components at this time. We hope the provided Hooks can help you build your own React Components into your app that adhere perfectly to your branding and design guides.