Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

use_favicon

Reactive favicon.

Demo

Usage

use leptos::prelude::*;
use leptos_use_favicon::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_favicon::{use_favicon_with_options, UseFaviconOptions};
use leptos_use_preferences::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

Make sure you follow the instructions in Server-Side Rendering.

On the server only the signals work but no favicon will be changed obviously.

Installation

cargo add leptos-use-favicon

Options

UseFaviconOptions

Options for use_favicon_with_options.

Every option is set with a builder method of the same name, e.g. UseFaviconOptions::default().new_icon(...). See also the API docs.

new_icon

Type: MaybeRwSignal<Option<String>>

New input favicon. Can be a RwSignal in which case updates will change the favicon. Defaults to None.

base_url

Type: String

Base URL of the favicon. Defaults to “”.

rel

Type: String

Rel attribute of the tag. Defaults to “icon”.

Source

Source • Demo • Docs