snapped async fn
This commit is contained in:
@@ -121,14 +121,15 @@ impl Component for RandomCommit {
|
||||
}
|
||||
//Generate Struct and implement component for driver using CommonDriver
|
||||
struct Driver {
|
||||
driver: FetchState<CommonDriver>,
|
||||
driver: FetchState<String>,
|
||||
}
|
||||
//implement the component for Driver using a string
|
||||
impl Component for Driver {
|
||||
type Message = Msg<CommonDriver>;
|
||||
type Message = Msg<String>;
|
||||
type Properties = ();
|
||||
fn create(_ctx: &Context<Self>) -> Self {
|
||||
Self {
|
||||
driver: FetchState::NotFetching, //Default state is not fetching anything
|
||||
driver: FetchState::NotFetching,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -164,12 +165,11 @@ impl Component for Driver {
|
||||
}
|
||||
|
||||
fn view(&self, ctx: &Context<Self>) -> Html {
|
||||
//render the component into HTML
|
||||
match &self.driver {
|
||||
FetchState::NotFetching => html! {
|
||||
<>
|
||||
<button onclick={ctx.link().callback(|_| Msg::GetData)}>
|
||||
{ "Get driver info" }
|
||||
{ "Get driver" }
|
||||
</button>
|
||||
<button onclick={ctx.link().callback(|_| Msg::GetError)}>
|
||||
{ "Get using incorrect URL" }
|
||||
@@ -177,10 +177,7 @@ impl Component for Driver {
|
||||
</>
|
||||
},
|
||||
FetchState::Fetching => html! { "Fetching" },
|
||||
FetchState::Success(data) => match data.clone().use_it() {
|
||||
Ok(html) => html,
|
||||
Err(err) => html! { err },
|
||||
},
|
||||
FetchState::Success(data) => html! { <p> {data} </p> },
|
||||
FetchState::Failed(err) => html! { err },
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user