63 releases

0.6.11 Apr 10, 2024
0.6.9 Mar 4, 2024
0.5.4 Nov 28, 2023
0.5.0-alpha2 Jul 29, 2023
0.0.3 Nov 27, 2022

#1815 in Web programming

Download history 2516/week @ 2024-01-01 2927/week @ 2024-01-08 4192/week @ 2024-01-15 3718/week @ 2024-01-22 4586/week @ 2024-01-29 4569/week @ 2024-02-05 3529/week @ 2024-02-12 5319/week @ 2024-02-19 5382/week @ 2024-02-26 6322/week @ 2024-03-04 5410/week @ 2024-03-11 5032/week @ 2024-03-18 5941/week @ 2024-03-25 6774/week @ 2024-04-01 5698/week @ 2024-04-08 6663/week @ 2024-04-15

25,519 downloads per month
Used in 28 crates (23 directly)

MIT license

120KB
1.5K SLoC

Leptos Meta

Leptos Meta allows you to modify content in a document’s <head> from within components using the Leptos web framework.

Document metadata is updated automatically when running in the browser. For server-side rendering, after the component tree is rendered to HTML, MetaContext::dehydrate can generate HTML that should be injected into the <head> of the HTML document being rendered.

use leptos::*;
use leptos_meta::*;

#[component]
fn MyApp() -> impl IntoView {
    // Provides a [`MetaContext`], if there is not already one provided.
    provide_meta_context();

    let (name, set_name) = create_signal("Alice".to_string());

    view! {
      <Title
        // reactively sets document.title when `name` changes
        text=move || name.get()
        // applies the `formatter` function to the `text` value
        formatter=|text| format!("{text}” is your name")
      />
      <main>
        <input
          prop:value=move || name.get()
          on:input=move |ev| set_name.set(event_target_value(&ev))
        />
      </main>
    }
}

Feature Flags

  • csr Client-side rendering: Generate DOM nodes in the browser
  • ssr Server-side rendering: Generate an HTML string (typically on the server)
  • hydrate Hydration: use this to add interactivity to an SSRed Leptos app
  • stable By default, Leptos requires nightly Rust, which is what allows the ergonomics of calling signals as functions. Enable this feature to support stable Rust.

Important Note: You must enable one of csr, hydrate, or ssr to tell Leptos which mode your app is operating in.

Dependencies

~19–32MB
~492K SLoC