65 releases

0.7.0-preview2 Apr 29, 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

#5 in #meta

Download history 4153/week @ 2024-01-31 4055/week @ 2024-02-07 4488/week @ 2024-02-14 5104/week @ 2024-02-21 6143/week @ 2024-02-28 5992/week @ 2024-03-06 4742/week @ 2024-03-13 5935/week @ 2024-03-20 6159/week @ 2024-03-27 6130/week @ 2024-04-03 5881/week @ 2024-04-10 6607/week @ 2024-04-17 6125/week @ 2024-04-24 4927/week @ 2024-05-01 6131/week @ 2024-05-08 4807/week @ 2024-05-15

22,983 downloads per month
Used in 28 crates (24 directly)

MIT license

180KB
3.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

~20–33MB
~540K SLoC