liveBook · Manning

Wrapper

As explained in Web Component Development with Modern Libraries and Tooling

An adapter layer that exposes web components through conventions or APIs native to a particular application framework.

A wrapper is an adapter layer that makes a web component feel native inside an application framework. Stencil can generate wrappers for React, Angular, and Vue, reducing the friction of using custom elements with framework conventions and APIs. section 6.1 section 6.15

Generating a React wrapper requires installing the React output target, adding reactOutputTarget to stencil.config.ts, updating package exports, and running the build. The build creates a sibling react-library directory containing generated component definitions. section 6.15

Using a generated React wrapper

A React application imports SortableTable from its generated stencil components and uses it as JSX: <SortableTable data={data} headings="Make,Model,Year" properties="make,model,year" />. The component remains a Stencil web component, while the wrapper makes its use resemble an ordinary React component. section 6.15

Listing 6.34 stencil.config.ts
import { reactOutputTarget } from '@stencil/react-output-target';

export const config: Config = {
  ...
  outputTargets: [
    ...
    reactOutputTarget({
      outDir: '../react-library/src/components/stencil-generated',
    })
  ],
};

Inspect the output-target configuration that directs Stencil to generate React wrapper files. section 6.15

Listing 6.36 src/App.tsx
import './App.css';
import { SortableTable } from './stencil/components';

const data = [
  { make: 'Ford', model: 'Mustang', year: 1967 },
  { make: 'Audi', model: 'A4', year: 2008 },
  { make: 'BMW', model: 'M3', year: 1999 },
];

export default function App() {
  return (
    <main>
      <h1>Sortable Table Demo</h1>
      <SortableTable
        data={data}
        headings="Make,Model,Year"
        properties="make,model,year"
      />
    </main>
  );
}

Inspect a complete React usage example with component import, sample table data, and JSX properties. section 6.15

How Web Component Development with Modern Libraries and Tooling covers it

How deep it goes
Explains the adapter purpose and gives React generation steps, configuration, package exports, build output, and usage, but not wrapper internals.
Examples
Demonstrates generated React components with SortableTable, Vite project commands, stencil.config.ts, package exports, and src/App.tsx.
What it assumes
Assumes a Stencil project and a React application, while showing the required output-target package, configuration, exports, and generated-file placement.
What you can do after
Builds React wrappers with @stencil/react-output-target and uses generated components in JSX.
How it connects
Connects web components with Stencil, React, Angular, Vue, JSX, custom elements, and package configuration.

Also explained in

Compare how 7 books explain wrapper →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Web Component Development with Modern Libraries and Tooling. The section links point to the parts of the book it draws on.