React
Render the Core AR element in React 19 and type it in TypeScript.
Core AR has no React package: React 19 renders custom elements as they are. React 19 is required. With React 18 or older, follow the JavaScript tab of the Quickstart, because React 18 passes attributes to custom elements only as text and does not attach their events.
Rendering
'use client'
import { useEffect } from 'react'
export function ViewInAr({ objectId, variantId }: { objectId: string; variantId?: string }) {
useEffect(() => {
import('@vizbl/core-ar').then(({ registerCoreArWidgets }) => registerCoreArWidgets())
}, [])
return (
<vizbl-core
api-key="pk_live_YOUR_PUBLISHABLE_KEY"
type="ar-viewer"
object-id={objectId}
variant-id={variantId}
/>
)
}- The key is
api-key. React keepskeyfor itself and never passes it to the element. - Attributes keep their HTML names, with dashes:
object-id, notobjectId.classNamebecomesclasson the element, as on any tag; to style the button inside, usetrigger-class. - Booleans are JSX booleans:
unstyledorunstyled={isPlain}. - Events are
onfollowed by the event's exact name:oncore-ar-readyandoncore-ar-error. See Events. - A label you put inside the element moves into its button. Keep it fixed: see Customization.
The element needs the browser: register it in an effect or another client-only place. Rendering the tag on the server is fine; it becomes a button once registered.
TypeScript
React does not know <vizbl-core>. Declare it once in your project, for example in vizbl-core.d.ts:
import type { CoreArWidgetEventDetail, CoreArWidgetType } from '@vizbl/core-ar'
import type { HTMLAttributes } from 'react'
type CoreArEventHandler = (event: CustomEvent<CoreArWidgetEventDetail>) => void
declare module 'react' {
namespace JSX {
interface IntrinsicElements {
'vizbl-core': HTMLAttributes<HTMLElement> & {
'type': CoreArWidgetType
'object-id': string
'api-key'?: string
'variant-id'?: string
'size-type'?: 'cm' | 'inch'
'dimension-axes'?: string
'camera-orbit'?: string
'min-camera-orbit'?: string
'max-camera-orbit'?: string
'trigger-class'?: string
'unstyled'?: boolean
'oncore-ar-ready'?: CoreArEventHandler
'oncore-ar-error'?: CoreArEventHandler
}
}
}
}