Skip to main content
vanilla-js exports web components, allowing for integration with frameworks like Vue.js and Svelte, or no frameworks at all. Components must first be registered with customElements.define(), then have a Stytch client and config passed in. They can still appear in HTML first but they will not render anything until they are registered and configured.
Most properties can also be updated. This can be used to, for example, update the component when the user switches themes. For object and array properties, a new object or array must be passed in.

Custom element registration

Custom elements must only be defined once, so when used in reusable components we recommend adding a check to the customElements.define() call.

Stytch client

We recommend defining the Stytch client as a singleton in a separate file so it is only initialized once.
stytch.js

Events

For easier binding, Stytch UI also implements callbacks as custom DOM events. These are more verbose than using callbacks directly but your framework may have better syntax for binding listeners. See callbacks for Login component and callbacks for Identity Provider for more information.

Shadow DOM

To isolate component CSS and DOM from the outside, the shadow attribute or constructor parameter can be used. This can be useful if you find Stytch UI components being affected by the page’s CSS or JavaScript. See the MDN article on shadow DOM for more information.

flushRender()

Components only update after the next microtask. In the rare case you need the DOM to immediately update, call flushRender() after setting the property.

Framework integration examples

Vue.js

Stytch UI can be used directly in Vue.js as a custom element. To avoid component resolution warnings during development, see how to set isCustomElement compiler option.
stytch.js
StytchLogin.vue

Svelte

Stytch UI can be used directly in Svelte as a custom element.
stytch.js
StytchLogin.svelte