82label

Docs › Web component and frameworks

React and Vue

Using @82label/core from React and Vue.

print() is a plain function: call it from any framework. Dedicated React and Vue packages are coming; the core is enough, as below.

React

import { useState } from 'react';
import { print } from '@82label/core';
import template from './labels/product.json';

export function PrintLabelButton({ items }) {
  const [busy, setBusy] = useState(false);
  const onClick = async () => {
    setBusy(true);
    try {
      const rows = items.map((it) => ({ name: it.name, price: it.price, sku: it.sku }));
      const r = await print(template, rows);
      if (r.status === 'pending_permission') alert('Allow this site in the print agent.');
    } finally {
      setBusy(false);
    }
  };
  return <button onClick={onClick} disabled={busy}>Print labels</button>;
}

Preview (React)

import { renderToSVG } from '@82label/core';

export function LabelPreview({ template, row }) {
  // renderToSVG escapes every value, so the markup is safe to insert
  return <div dangerouslySetInnerHTML={{ __html: renderToSVG(template, row) }} />;
}

Vue

<script setup>
import { ref } from 'vue';
import { print } from '@82label/core';
import template from './labels/product.json';

const props = defineProps({ items: Array });
const busy = ref(false);

async function onPrint() {
  busy.value = true;
  try {
    await print(template, props.items.map((it) => ({ name: it.name, price: it.price, sku: it.sku })));
  } finally {
    busy.value = false;
  }
}
</script>

<template>
  <button :disabled="busy" @click="onPrint">Print labels</button>
</template>

As a web component

<label-82> is a standard custom element, so React 19 and Vue 3 can use the tag directly. In Vue, add label-82 to compilerOptions.isCustomElement.

import { defineLabelElement } from '@82label/core';
import '@82label/core/styles.css';
defineLabelElement();

// React 19
<label-82 template="lbl_a1b2c3d4e5" data={JSON.stringify(rows)} button="Print" />