Widgets usage in React project
Widget usage in React context is in preview.
In order to use the widgets in a React context, your app has to import the Raylo Pay react script dynamically, and set it up before usage.
This page shows an example of the different parts needed to make it work.
1. Import and set up Raylo Pay widgets
// raylopay.js:
import React from 'react';
// export settings to use in the widgets
// these would normally be set at build time or retrieved from your backend
export const merchantId = '<constant, provided by Raylo>';
export const scriptOrigin = process.env.NODE_ENV === 'production'
? 'https://widgets.raylopay.com'
: 'https://widgets.staging.raylopay.com';
// import widgets script
// the argument to import() has to be a constant expression, see https://webpack.js.org/api/module-methods/#dynamic-expressions-in-import
const { RayloPayIntegration, RayloPayProductWidget, RayloPayCheckoutWidget } =
process.env.NODE_ENV === 'production'
? await import('https://widgets.raylopay.com/react/raylopay.js')
: await import('https://widgets.staging.raylopay.com/react/raylopay.js');
// initialize environment
RayloPayIntegration.init({ React, scriptOrigin });
// export react components
export { RayloPayProductWidget, RayloPayCheckoutWidget };2. Using the widgets in your app
After the initial setup, you can use the widgets in your app. Here is a minimal example app:
Widget properties
Both widgets support the props mentioned in the Widget properties page.
...props
...propsAdditionally the react widgets will also forward additional props to the container created for the widget; use these to set props like id, className, style, etc.
In the example app above, className is handled as one of those extra props.
Last updated
Was this helpful?