Strugling with creating interval in a yew component

Hi everyone

I am trying to build a simple application similar to Dontpad but in yew.
The main thing that this component needs to do is to send a request every 5 seconds to the server ,get response , and then update the textarea in the page.

here is my code:

pub struct Props{
    pub url:String,

pub struct Page{
    pub text:String
impl Component for Page {
    type Message=();
    type Properties=Props;

    fn create(ctx: &Context<Self>) -> Self {
        let url = ctx.deref().props().url.clone();
        let mut textarea_text="".to_string();
        let interval = Interval::new(5000,move|| {send_request(ctx, url)} ); //Error 
    fn view(&self, ctx: &Context<Self>) -> Html {
        html! {
        <ToolBar url={"test"}/> 
            <div class="container-fluid">
                <textarea id="textarea" class={classes!("textarea",css!("white-space:pre-wrap;"))} value={ctx.props().inner_text.clone()} >
    fn update(&mut self, ctx: &Context<Self>, msg: Self::Message) -> bool {

pub fn send_request(ctx:&Context<Page>,url:String){
let url = url.clone();
wasm_bindgen_futures::spawn_local(async move{
    let _url = format!("{}",url);
    // log!(&_url);
    // log!("sdfasdfas");
    let response = Request::get(_url.as_str())
    need to change textarea value to response here

    ctx.props().inner_text=response; //Error


as you might know due to life time issues i can not pass ctx to send_request function and I am getting

borrowed data escapes outside of associated function
`ctx` escapes the associated function body here


so I am struggling with this particular problem and I don't know how to solve it.

Anyone has an idea?

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.