@wearejh/m2-pwa-currency

> TODO: description

Usage no npm install needed!

<script type="module">
  import wearejhM2PwaCurrency from 'https://cdn.skypack.dev/@wearejh/m2-pwa-currency';
</script>

README

@wearejh/m2-pwa-currency

Note: This does NOT currently affect Quotes, it's only purpose currently is to track the selected currency so that content can be rendered/updated.

Install

npm i @wearejh/m2-pwa-currency

Browser installation

This modules gives you a register function for state & events, along with an apollo link that will add a header to outgoing requests.

import { init } from '@wearejh/m2-pwa-engine/lib/browser';
import { createCurrencyBrowser } from '@wearejh/m2-pwa-currency';

const { link, register } = createCurrencyBrowser();

const createApp = init({
    features: [register()],
    links: [link],
    // the rest of the params to init
});

Server installation

For initial rendering, you'll want to read the content-currency cookie and use that to set some initial state.

import { createCurrencySSR } from '@wearejh/m2-pwa-currency';

const { reducers, state } = createCurrencySSR(req.cookies['content-currency']);

const { App, Inner } = getSsrInit({
    state: {
        ...state,
    },
    reducers: {
        ...reducers,
    },
});