Merge pull request #138 from mrxiaozhuox/master

fix: `dog-app` breed change
This commit is contained in:
Jonathan Kelley 2022-01-19 08:19:11 -05:00 committed by GitHub
commit 8c7473d194
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

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 {