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.
Custom element registration
Custom elements must only be defined once, so when used in reusable components we recommend adding a check to thecustomElements.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 usingcallbacks 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, theshadow 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, callflushRender() 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 setisCustomElement compiler option.
stytch.js
StytchLogin.vue
Svelte
Stytch UI can be used directly in Svelte as a custom element.stytch.js
StytchLogin.svelte