Skip to content

is #[component] #5674

Description

@morvoxa

use std::collections::HashMap;

use dioxus::prelude::*;

const TAILWIND_CSS: Asset = asset!("/assets/tailwind.css");

fn main() {
dioxus::launch(App);
}

#[component]

fn App() -> Element {
let mut sig = use_signal(|| 0);
let mut img_src = vec![
"https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcTDeRKEc_fh-irEXEAortEqnG0f0cTp8Yh33ic2FV8BtA&s=10",
"https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcS50y4apASDsBzHp4Q_r_D7-8I6HhaYLJM8hqp9i_iy2w&s=10"];
let current_val = *sig.read();
let index = if current_val >= 0 {
current_val as usize
} else {
0
};
let img_val = img_src.get(index).unwrap_or(&img_src[0]);
rsx! {
document::Stylesheet { href: TAILWIND_CSS }
Top {}
Display { img: img_val }
NavImg { x: sig }
}
}
#[component]
fn Top() -> Element {
rsx! {
div {
h1 { id: "titile", class: "text-center text-green-500", "Image" }
}
}
}
#[component]
fn Display(img: String) -> Element {
rsx! {
div { id: "display", class: "flex justify-center m-6",
img { class: "text-center w-40 h-40", src: "{img}" }
}
}
}
#[component]
fn NavImg(x: Signal) -> Element {
rsx! {
div { class: "flex gap-4 justify-center",
button {
onclick: move || *x.write() += 1,
id: "next",
class: "bg-green-500",
"Next"
}
button {
onclick: move |
| *x.write() -= 1,
id: "prev",
class: "bg-green-500",
"Prev"
}
h1 { "{x}" }
}
}
}

i try dioxus , but in func Display i declare img : String but the img_val from App is &&str , what happen here because my app is work compile success can some one tellme .

the problem that i dont uderstand is why &&str can put in String : hope fully some one answer

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions