dioxus/examples/core_reference/basics.rs

38 lines
805 B
Rust
Raw Normal View History

2021-07-16 16:11:25 -04:00
//! Example: The basics of Dioxus
//! ----------------------------
//!
//! This small example covers some of the basics of Dioxus including
//! - Components
//! - Props
//! - Children
//! - the rsx! macro
2021-07-02 01:30:52 -04:00
use dioxus::prelude::*;
2021-12-28 23:48:25 -05:00
pub static Example: Component = |cx| {
2021-07-02 01:30:52 -04:00
cx.render(rsx! {
div {
2021-07-16 16:11:25 -04:00
Greeting {
name: "Dioxus"
div { "Dioxus is a fun, fast, and portable UI framework for Rust" }
}
}
})
};
2021-07-02 01:30:52 -04:00
2021-07-16 16:11:25 -04:00
#[derive(PartialEq, Props)]
struct GreetingProps {
name: &'static str,
}
static Greeting: Component<GreetingProps> = |cx| {
2021-07-16 16:11:25 -04:00
cx.render(rsx! {
div {
h1 { "Hello, {cx.props.name}!" }
2021-10-24 19:30:36 +02:00
p { "Welcome to the Dioxus framework" }
2021-07-16 16:11:25 -04:00
br {}
{cx.children()}
2021-07-02 01:30:52 -04:00
}
})
};