Updated the docs

This commit is contained in:
2024-12-24 14:41:07 +01:00
parent 60fb444bc1
commit 96fbf15a3c
+24
View File
@@ -0,0 +1,24 @@
---
title: Component
---
A `Component` is a function but in the backend it's a struct. It's a struct because of named parameters. It can be defiend using the `#[component]` attribute.
```rust
#[component]
pub fn App() -> Element {
rsx! {
User { name: "leo", age: 15 }
}
}
#[component]
pub fn User<'a>(name: &'a str, age: u8) {
rsx! {
text { static "Welcome {}! You are {} years old!", self.name, self.age }
}
}
```
If you're wondering why `User` doesn't have a return type, it's because the `#[component]` attribute sets it automatically, You can also use a custom return type.
The `text` is static because self.name is a reference, dynamic text needs the lifetimes to be `'static`.