What is the best way handle String in multiple closures? #5319
Unanswered
canyon-service
asked this question in
Q&A
Replies: 3 comments
|
Also I have something similar to: Here id is an integer, if it is a string it is not even possible to clone to the async onclick unless I am missing something |
0 replies
|
https://docs.rs/dioxus/0.7.3/dioxus/prelude/macro.to_owned.html |
0 replies
|
The idiomatic Dioxus way is the #[component]
fn TestComponent() -> Element {
let path_loader: Loader<Vec<String>> = use_loader(test_api)?;
rsx! {
for path in path_loader() {
div {
p { "path: {path}" }
input {
r#type: "checkbox",
oninput: {
to_owned![path];
move |event: Event<FormData>| {
info!("Selected {} {}", event.checked(), path);
}
},
}
button {
onclick: {
to_owned![path];
move |_| {
info!("Deleted {}", path);
}
},
"delete {path}"
}
button {
onclick: {
to_owned![path];
move |_| {
info!("Edit {}", path);
}
},
"edit {path}"
}
}
}
}
}
You can also clone multiple variables at once: @canyon-service regarding the onclick: {
to_owned![url];
move |_| async move {
// url is owned here
do_something(url).await;
}
}See the macro docs for details. |
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
I have a component that loops through a vector of Strings that is passed to multiple closures, one issue is that it cannot be passed to multiple closures. I have a fix to manually clone the String 2 times for 2 closures. Is there a better way of doing this?
Ugly fix
All reactions