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






