dioxus/examples/core_reference/basics.rs

39 lines
853 B
Rust
Raw Normal View History

2021-07-16 20:11:25 +00: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 05:30:52 +00:00
use dioxus::prelude::*;
pub fn Example(cx: Scope) -> Element {
2021-07-02 05:30:52 +00:00
cx.render(rsx! {
div {
2021-07-16 20:11:25 +00:00
Greeting {
name: "Dioxus"
div { "Dioxus is a fun, fast, and portable UI framework for Rust" }
}
}
})
}
2021-07-02 05:30:52 +00:00
2021-07-16 20:11:25 +00:00
#[derive(PartialEq, Props)]
struct GreetingProps<'a> {
2021-07-16 20:11:25 +00:00
name: &'static str,
children: Element<'a>,
2021-07-16 20:11:25 +00:00
}
pub fn Greeting<'a>(cx: Scope<'a, GreetingProps<'a>>) -> Element {
2021-07-16 20:11:25 +00:00
cx.render(rsx! {
div {
h1 { "Hello, {cx.props.name}!" }
2021-10-24 17:30:36 +00:00
p { "Welcome to the Dioxus framework" }
2021-07-16 20:11:25 +00:00
br {}
&cx.props.children
2021-07-02 05:30:52 +00:00
}
})
}