Overview
Svelte Loadable is a library that allows for dynamically loading Svelte components. It is inspired by react-loadable and provides similar functionality. With Svelte Loadable, developers can specify a loader method that returns an async module import for the desired component.
Features
- Loader method: Pass a loader method that imports the desired component to the Loadable component.
- Unloader functionality: Use the unloader to prevent caching of the component, causing the loader to be called each time the component is used after being unmounted.
- Props customization: Any additional props passed to the Loadable component will be directly passed onto the rendered component if the default slot is defined.
- Events: The Loadable component provides an
on:load event that is executed right after the component is loaded. - Customizable slots: Customize the loading, error, and timeout states of the component using the provided slots.
Installation
To install Svelte Loadable, follow these steps:
- Add the library to your project using your preferred package manager:
npm install svelte-loadable
- Import the Loadable component from the library in your Svelte component:
import Loadable from 'svelte-loadable';
- Use the Loadable component in your Svelte component by passing a loader method that returns an async module import:
- Customize the props and slots as needed to meet your requirements.
Summary
Svelte Loadable is a library that enables dynamic loading of Svelte components. It provides functionalities such as loader methods, unloader functionality, props customization, events, and customizable slots. By using Svelte Loadable, developers can optimize the loading and rendering of components in their Svelte applications.