React 18 and earlier
Use staticview components in React 18 and earlier, where JSX sets only attributes.
TypeScript Configuration
Add the component types to your TypeScript configuration:
{ "compilerOptions": { "types": [ // Required: types the component tags in the JSX of React 18 and earlier // For one component: "@staticview/ui/types/react18/[component-name]" "@staticview/ui/types/react18",
// Optional: types what `querySelector` and `createElement` return for each tag // For one component: "@staticview/ui/types/dom/[component-name]" "@staticview/ui/types/dom",
// Optional: declares each component type globally, with no import // For one component: "@staticview/ui/types/global/[component-name]" "@staticview/ui/types/global", ], },}Importing Web Components
Since components register globally, import each one once, in your app's entry point:
import "@staticview/ui/[component-name]";Setting Properties and Events
Since React 18 and earlier set only attributes from JSX, set properties and listen to events on the element through a ref:
const ref = useRef<ComponentName>(null);
useEffect(() => { const element = ref.current!; element.opened = isOpen; element.addEventListener("openedchange", handleOpenedChange); return () => element.removeEventListener("openedchange", handleOpenedChange);}, [isOpen]);
return <component-name ref={ref}></component-name>;Boolean Attributes
A boolean attribute is on whenever it is present, and close-button="false" turns the close button on. Since React 18 turns a boolean on a custom element into a string, close-button={false} also renders close-button="false". Pass "" to turn it on, and undefined to turn it off:
<component-name close-button={hasCloseButton ? "" : undefined}></component-name>Using Slots
Pass the content as children, with a slot attribute for a named slot:
<component-name> <span slot="title">Title</span> <span>Content</span></component-name>