JSX lets a component describe its rendered HTML with markup inside JavaScript or TypeScript code. For example, a radio-group component can return a fieldset containing a legend and radio buttons from its render method. Browsers do not understand JSX directly, so Stencil compiles its .tsx components into web components. section 6.7 section 6.1
A small render method
render() { return <fieldset><legend>{this.legend}</legend></fieldset>; } The braces insert the component’s legend value into the markup. A fuller radio group maps values to inputs and connects their change handler. section 6.7
Listing 6.6 radio-group.tsx
render() {
const labelArray = this.labels.split(',').map(value => value.trim());
const valueArray = this.values.split(',').map(value => value.trim());
return (
<fieldset>
<legend>{this.legend}</legend>
<slot name="before"></slot>
<div>
{valueArray.map((v, index) => (
<div>
<input
type="radio"
id={v}
name={this.name}
value={v} checked={v === this.value}
onChange={this.handleChange}
/>
<label htmlFor={v}>{labelArray[index]}</label>
</div>
))}
</div>
<slot name="after"></slot>
</fieldset>
);
}
The complete render method shows labels, radio inputs, slots, and an event handler together in JSX. section 6.7
JSX is a syntax choice, not a requirement for web components. Stencil uses it instead of tagged template literals and therefore requires a build step. When using custom elements in a React TypeScript app, JSX declarations can specify their accepted attributes and optional element references. In React 19, a JSX prop becomes an element property if a matching property exists; otherwise React sets an attribute. section 6.1 section 9.4
Listing 9.12 React jsx.d.ts
import "react";
declare module "react" {
namespace JSX {
interface IntrinsicElements {
"hello-world": {
name?: string;
ref?: any;
};
"radio-group": {
name: string;
labels: string;
ref?: any;
value: string;
values: string;
onChange?: (event: Event) => void;
};
}
}
}
The type declaration shows how a React TypeScript app makes two custom elements available in JSX. section 9.4








