use_favicon
Reactive favicon.
Demo
Usage
use leptos::prelude::*;
use leptos_use::use_favicon;
#[component]
fn Demo() -> impl IntoView {
let (icon, set_icon) = use_favicon();
set_icon.set(Some("dark.png".to_string())); // change current icon
view! { }
}
Passing a Source Signal
You can pass a Signal
to use_favicon_with_options
. Change from the source signal will be
reflected in your favicon automatically.
use leptos::prelude::*;
use leptos_use::{use_favicon_with_options, UseFaviconOptions, use_preferred_dark};
#[component]
fn Demo() -> impl IntoView {
let is_dark = use_preferred_dark();
let (icon, _) = use_favicon_with_options(
UseFaviconOptions::default().new_icon(
Signal::derive(move || {
Some((if is_dark.get() { "dark.png" } else { "light.png" }).to_string())
}),
)
);
view! { }
}
Server-Side Rendering
On the server only the signals work but no favicon will be changed obviously.
Feature
This function is only available if the crate feature
use_favicon
is enabled