67 releases

0.7.0-preview2 Apr 29, 2024
0.7.0-alpha Jun 28, 2024
0.6.9 Mar 4, 2024
0.5.4 Nov 28, 2023
0.0.3 Nov 27, 2022

#1525 in Web programming

Download history 5900/week @ 2024-04-04 5877/week @ 2024-04-11 6883/week @ 2024-04-18 5650/week @ 2024-04-25 5300/week @ 2024-05-02 6114/week @ 2024-05-09 5777/week @ 2024-05-16 6014/week @ 2024-05-23 7249/week @ 2024-05-30 5249/week @ 2024-06-06 5606/week @ 2024-06-13 6688/week @ 2024-06-20 5357/week @ 2024-06-27 3617/week @ 2024-07-04 7183/week @ 2024-07-11 6492/week @ 2024-07-18

23,642 downloads per month
Used in 31 crates (26 directly)

MIT license

200KB
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–32MB
~527K SLoC