Preact
TypeScript Configuration
Add the Web Component types to your TypeScript configuration:
{ "compilerOptions": { "types": [ // Required: Enables JSX type support for Preact "@staticbolt/wcp/types/preact",
// Optional: Adds native DOM types (e.g. `querySelector`, `document`) "@staticbolt/wcp/types/dom",
// Optional: Exposes component types globally (no imports needed) "@staticbolt/wcp/types/global", ], },}This provides TypeScript support for the web components in your Preact application.
Importing Web Components
Web components are registered globally in the browser. Import them once in your application’s entry point:
import "@staticbolt/wcp/[component-name]";Important: Do not import web components in multiple files. Import them only once at application startup.
Setting Properties and Attributes
If the web component has a JavaScript property, Preact will automatically set it, otherwise, it sets it as an HTML attribute.
<component-name opened={isOpen} close-button="false"></component-name>Handling Events
Use on[eventName] syntax to listen for custom events:
<component-name onopened={handleOpen}></component-name>Using Slots
Use children to render the content of the web component:
<component-name> <span slot="title">Title</span> <span>Content</span></component-name>