# Render

Render html with data from the api.
<br>
Keeps the UI in sync with the data.

## Usage

```javascript
import { render } from 'geta-checkout';
render(selector, template);
render.init(apiOptions);
```

## Render a built-in component

```html
<div data-add-to-cart='{"itemId": "1"}'></div>
```

```javascript
import { render, AddToCartUI } from 'geta-checkout';
render('[data-add-to-cart]', AddToCartUI);
```

<div class="example example--dark">
    <div data-add-to-cart='{"itemId": "1"}'></div>
</div>

## Render a string

```html
<div data-counter></div>
```

```javascript
import { render } from 'geta-checkout';
render('[data-counter]', function(props) {
    return props.cart.totalQuantity + ' items in cart';
});
```

<div class="example example--dark">
    <div data-counter></div>
</div>

## Render an ES6 template string

```html
<div data-counter></div>
```

```javascript
import { render } from 'geta-checkout';
const template = ({cart}) => `${cart.totalQuantity} items in cart`;
render('[data-counter]', template);
```

<div class="example example--dark">
    <div data-counter></div>
</div>

## Render a custom React component

```html
<div data-react-component></div>
```

```javascript
import React from 'react';
import { render } from 'geta-checkout';
import ReactComponent from './my-react-component';
render('[data-react-component]', ReactComponent);
```

<div class="example example--dark">
    <div data-react-component></div>
</div>

## Configure API endpoints

Call `render.init` and pass in the apis.
<br>
This will render the UI with initial data from the server (or the build-in mock server).

```javascript
import { render, mockServer, CartApi, CustomerApi, LanguageApi, PaymentApi, ShipmentApi } from 'geta-checkout';

const cartApi = new CartApi(server.cartServices);
const customerApi = new CustomerApi(server.customerServices);
const languageApi = new LanguageApi();
const paymentApi = new PaymentApi(server.paymentServices);
const shipmentApi = new ShipmentApi(server.shipmentServices);

render.init({
    cartApi: cartApi,
    customerApi: customerApi,
    languageApi: languageApi,
    paymentApi: paymentApi,
    shipmentApi: shipmentApi
});

cartApi.get();
customerApi.get();
languageApi.get();
paymentApi.get();
shipmentApi.get();
```
