Import the Zonos SDK
First, install the Zonos Elements package in your React project. This will automatically add the Zonos SDK as a peer dependency, and includes TypeScript typings out of the box for a better developer experience.
Terminal
npm install --save @zonos/zonos-elements-react
Configure the Zonos SDK
Once the Zonos Elements package is installed, you can configure the Zonos SDK in your React project. You need to have a Zonos account and API key to use Elements on your site.
The Elements React library exposes a ZonosProvider
component that you can use to configure the Zonos SDK. You can wrap your entire application in the ZonosProvider
component, or you can wrap only the components that use the Zonos SDK. We recommend storing your Zonos API key in an environment variable and passing it to the ZonosProvider
component as a prop for security reasons.
App.js
import { ZonosProvider } from '@zonos/zonos-elements-react';
export const App = () => (
<ZonosProvider config={{ apiKey: process.env.REACT_APP_ZONOS_API_KEY }}>
{/* The rest of app goes here */}
</ZonosProvider>
);
Create a Totals element
To create a Totals element, use the Totals
component from the Zonos Elements React library. You will need to pass in a LandedCost
object from the Zonos API, which will be automatically formatted and displayed as an itemized breakdown, complete with localized currency.
JavaScript
import { Totals } from '@zonos/zonos-elements-react';
export const YourComponent = () => (
<div>
{/* The rest of your component goes here */}
<Totals
landedCost={/* Reference to your landed cost object here */}
/>
{/* The rest of your component goes here */}
</div>
);
Totals element
Learn how to display landed cost as an itemized cart breakdown with the Totals element.
The Totals element allows you to display a complete breakdown of each line item that goes into a landed cost calculation. This includes the item price, shipping cost, duties and taxes, and any other fees that are included in the landed cost calculation. The Totals element is a great way to show your customers exactly what they're paying for and why.