How to call a callback that changes state after a promise is done? #20
Replies: 1 comment
-
|
This follows from Rust's ownership rules. Initially, fn render(&self) -> VNode {Then, it moves to a .on_click(&Callback::new(move |_| {Finally, you try to move it to: spawn_local(async move {However, this last move is illegal, since the fn render(&self) -> VNode {
let mut callback = self.callback.clone();
h!(button)
.on_click(&Callback::new(move |_| {
spawn_local({
let mut callback = callback.clone();
async move {
JsFuture::from(Promise::resolve(&JsValue::UNDEFINED))
.await
.unwrap();
callback();
}
);
}))
.build("Click me")
} |
Beta Was this translation helpful? Give feedback.
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.
-
Code: https://github.com/ChocolateLoverRaj/wasm-react/blob/22e907110b0bc5156669d3c0c268d774432f8380/examples/01-hello-world/src/lib.rs#L47-L69
I get this error:
How to change the code to achieve the desired result without Rust errors?
Beta Was this translation helpful? Give feedback.
All reactions