seokju-na / react-thermal-printer

React for thermal printing
MIT License
298 stars 42 forks source link

feat: support custom components inside `<Printer>` elem #80

Closed seokju-na closed 2 weeks ago

seokju-na commented 2 weeks ago

resolves #79

Currently, custom components were not supported inside <Printer> child nodes, so a renderer function had to be used rather than a component.

This PR improves support for custom components (both function component and class component).

ASIS:

import { render, Printer, Text } from 'react-thermal-printer';

function renderCustomText(text: string) {
  return <Text>Text: {text}</Text>;
}

const data = await render(
  <Printer type="epson">
    {renderCustomText('Hello World')}
  </Printer>
);

TOBE:

import { render, Printer, Text } from 'react-thermal-printer';

function CustomText(props: { children: string }) {
  return <Text>Text: {props.children}</Text>;
}

const data = await render(
  <Printer type="epson">
    <CustomText>Hello World</CustomText>
  </Printer>
);

Minor changes: