Embedded Components React Integration
Learn how to use Payabli’s embedded components in your React application.
Payabli’s Embedded Components can be used in a React application following the same configuration patterns as in a vanilla JavaScript application.
Visit the React Integration Example to see Payabli’s embedded components in a React application.
Usage
See Library URLs for important information about embedded components library URLs.
Step 1: Create the hook
Create a hook that allows you to use the embedded component and execute its methods.
The hook needs to inject the Payabli library script and initialize the embedded component with the provided configuration.
Make a new file for the usePayabli
hook and add the following code:
The hook receives the following arguments:
options
: The configuration object for the embedded component.method
: The method to execute inpayabliExec
.parameters
: An optional structure that lets you pass objects to themethod
(example:paymentMethod
,paymentDetails
, orcustomerData
).production
: A boolean value that determines whether to use the production or sandbox environment. By default, this is set tofalse
.
The hook returns an array with the following elements:
payOptions
: The configuration object for the embedded component.setPayOptions
: A function to update the configuration object.payabliExec
: A function to execute the embedded component’s method.payabliReinit
: A function to reinitialize the embedded component.
Step 2: Create the component
Create a new PayabliCheckout
component that passes in the configuration object for the embedded component to the usePayabli
hook.
The PayabliCheckout
component uses the payabliExec
function to execute the embedded component’s method.
Create a new file in the same directory and add the following code:
There are multiple types of embedded components with different use cases. See the Embedded Components Overview to decide which component type is best for you.
Was this page helpful?