Getting Started with Svelte
VistaView provides a VistaView Svelte component (recommended) and a lower-level useVistaView hook for advanced use cases.
Installation
Section titled “Installation”Component-first usage (recommended)
Section titled “Component-first usage (recommended)”The recommended, primary way to use VistaView in Svelte is the VistaView component. It handles lifecycle, DOM changes, and provides a simple imperative API via bind:this and getApi().
Basic example
Section titled “Basic example”Imperative Control
Section titled “Imperative Control”If you need programmatic access to the gallery API, use the vistaRef callback prop:
Options
Section titled “Options”Extensions
Section titled “Extensions”Tip: prefer the component when your gallery content is dynamic, as it observes DOM changes and re-initializes automatically.
Hook approach (advanced)
Section titled “Hook approach (advanced)”The useVistaView hook is a lower-level API. Use it for non-component contexts or when you need manual control. The hook handles lifecycle internally (onMount/onDestroy), so you can call it at the top level.
Low-level usage
Section titled “Low-level usage”You can call the core vistaView function directly when embedding in non-component contexts:
SvelteKit
Section titled “SvelteKit”Use the VistaView component in SvelteKit apps; it handles lifecycle and DOM updates automatically. If you need the hook, initialize it inside onMount to avoid SSR issues.
Best practices & troubleshooting
Section titled “Best practices & troubleshooting”- Prefer the component for most cases (dynamic content, SvelteKit, simpler lifecycle).
- Keep
optionsobjects stable (define outside render scope) to avoid unnecessary re-initializations. - Use optional chaining (e.g.,
comp?.getApi()?.vistaView?.open(0)) when calling methods that may not be ready yet. - If using the hook and the DOM changes dynamically, re-initialize or prefer the component.
Next Steps
Section titled “Next Steps”- Explore configuration options
- Learn about extensions
- Customize the styling