From 96fbf15a3c343146c7db221ec19b74b860df6a4f Mon Sep 17 00:00:00 2001 From: Leo dev Date: Tue, 24 Dec 2024 14:41:07 +0100 Subject: [PATCH] Updated the docs --- docs/references/component.md | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 docs/references/component.md diff --git a/docs/references/component.md b/docs/references/component.md new file mode 100644 index 0000000..ff04453 --- /dev/null +++ b/docs/references/component.md @@ -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`. \ No newline at end of file