hello ,
I am new to rust and I am trying to build a front-end app using yew.rs
I want to use state to show some texts in textarea that I am getting from server.
but I am getting this error
on state
here is my code :
use std::{clone, ops::Deref};
use gloo::console::log;
use reqwasm::http::Request;
use serde::{Serialize, Deserialize};
use yew::prelude::*;
use yew_router::{prelude::*,};
use crate::components::molecules::toolbar::ToolBar;
#[derive(Serialize,Deserialize,Clone)]
struct DataResponse{
text : String
}
#[derive(Properties,PartialEq)]
pub struct Props{
pub url:String,
}
#[function_component(Page)]
pub fn first(props:&Props)->Html{
// let navigator = use_navigator().unwrap();
// let onclick = Callback::from(move |_| navigator.push(&Route::Home));
let state = use_state(||{
DataResponse{
text: "".to_owned()
}
});
let url = props.url.clone();
wasm_bindgen_futures::spawn_local(async move{
let state = state.clone();
let _url = format!("http://127.0.0.1:3000/{}",url);
log!(&_url);
log!("sdfasdfas");
let response = Request::get(_url.as_str())
.send()
.await
.unwrap()
.text()
.await
.unwrap();
let mut dataresponse = state.deref().clone();
dataresponse.text = response;
state.set(dataresponse);
log!(&response)
});
html! {
<>
<div>
<ToolBar url={props.url.clone()}/>
<div class="container-fluid">
<textarea name={"text"} value={*state.clone().text}>
</textarea>
</div>
</div>
</>
}
}
and this is the exact error message on line value={state.clone()}
:
the trait bound `UseStateHandle<DataResponse>: IntoPropValue<std::option::Option<implicit_clone::unsync::IString>>` is not satisfied
the following other types implement trait `IntoPropValue<T>`:
<&'a str as IntoPropValue<StyleSource>>
<&'static [(K, V)] as IntoPropValue<implicit_clone::unsync::IMap<K, V>>>
<&'static [T] as IntoPropValue<implicit_clone::unsync::IArray<T>>>
<&'static str as IntoPropValue<Classes>>
<&'static str as IntoPropValue<implicit_clone::unsync::IString>>
<&'static str as IntoPropValue<std::option::Option<implicit_clone::unsync::IString>>>
<&'static str as IntoPropValue<std::option::Option<std::string::String>>>
<&'static str as IntoPropValue<std::string::String>>
and 29 others
thank you for your help