use_service_worker
Reactive ServiceWorker API.
Please check the working example.
Usage
use leptos::prelude::*;
use leptos_use_service_worker::{use_service_worker_with_options, UseServiceWorkerOptions, UseServiceWorkerReturn};
#[component]
fn Demo() -> impl IntoView {
let UseServiceWorkerReturn {
registration,
installing,
waiting,
active,
skip_waiting,
check_for_update,
} = use_service_worker_with_options(UseServiceWorkerOptions::default()
.script_url("service-worker.js")
.skip_waiting_message("skipWaiting"),
);
view! { }
}
SendWrapped Return
The returned closures check_for_update and skip_waiting are sendwrapped functions. They can
only be called from the same thread that called use_service_worker.
Server-Side Rendering
Make sure you follow the instructions in Server-Side Rendering.
This function does not support SSR. Call it inside a create_effect.
Installation
cargo add leptos-use-service-worker
Options
UseServiceWorkerOptions
Options for use_service_worker_with_options.
Every option is set with a builder method of the same name, e.g. UseServiceWorkerOptions::default().script_url(...). See also the API docs.
script_url
Type: String
The name of your service-worker file. Must be deployed alongside your app. The default name is ‘service-worker.js’.
skip_waiting_message
Type: String
The message sent to a waiting ServiceWorker when you call the skip_waiting callback.
The callback is part of the return type of use_service_worker!
The default message is ‘skipWaiting’.
on_controller_change
Type: Arc<dyn Fn()>
What should happen when a new service worker was activated? The default implementation reloads the current page.