DOCS

Items element

/

Items element

Learn how to display a localized shopping cart on your site with the Items element.

The Items element allows you to pass in a list of items to display a localized shopping cart on your site.

Zonos Items element example

1

Import the Zonos SDK

React
Vanilla JavaScript

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

1
npm install --save @zonos/zonos-elements-react
2

Configure the Zonos SDK

React
Vanilla JavaScript

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

1
2
3
4
5
6
7
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>
);
3

Create an Items element

React
Vanilla JavaScript

To create an Items element, import the Items component from the Zonos Elements React library and pass in the items you want to display in the cart. The Items component will automatically display the localized shopping cart on your site where you place the component.

JavaScript

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
import { Items } from '@zonos/zonos-elements-react';

export const Cart = () => (
  <Items
    items={[
      {
        id: '123',
        name: 'Test Product',
        price: 100,
        currencyCode: 'USD',
        quantity: 1,
        imageUrl: 'https://example.com/image.jpg',
        url: 'https://example.com/product',
      },
    ]}
  />
);

Zonos Items element example

Was this page helpful?


© 2023 Zonoszonos.com