fix: `dog-app` breed change

This commit is contained in:
YuKun Liu 2022-01-19 20:14:41 +08:00
parent 2073b400df
commit 16d2074fcf
1 changed files with 7 additions and 1 deletions

View File

@ -61,7 +61,7 @@ fn app(cx: Scope) -> Element {
#[inline_props]
fn Breed(cx: Scope, breed: String) -> Element {
#[derive(serde::Deserialize)]
#[derive(serde::Deserialize, Debug)]
struct DogApi {
message: String,
}
@ -72,6 +72,12 @@ fn Breed(cx: Scope, breed: String) -> Element {
reqwest::get(endpoint).await.unwrap().json::<DogApi>().await
});
let breed_name = use_state(&cx, || breed.clone());
if breed_name.get() != breed {
breed_name.set(breed.clone());
fut.restart();
}
cx.render(match fut.value() {
Some(Ok(resp)) => rsx! {
button {