Apply whitespaces in yew string in a tag

i am building a yew application and I send a request to server for getting a text to show it on a textarea tag

the response is sth like "hello\nit is for \ntest"
i want to be shown like this in my textarea tag

it is for 

but it shows just like the response and i dont know how can i apply those whitespaces on that string tag.
anyone has an idea?
here is my code

struct DataResponse{
    text : String
pub struct Props{
    pub url:String,

pub struct Page;

impl Component for Page {
    type Message=();

    type Properties=Props;

    fn create(ctx: &Context<Self>) -> Self {
        let url = ctx.deref().props().url.clone();
        let interval = Interval::new(5000,move|| send_request(url.clone()) );


    fn view(&self, ctx: &Context<Self>) -> Html {

            html! {
        <ToolBar url={"test"}/> 
            <div class="container-fluid">
                <textarea id="textarea" class="textarea" >
                    {"hello i am here"}
    fn update(&mut self, ctx: &Context<Self>, msg: Self::Message) -> bool {

fn send_request(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())

        let textarea:Element = document().get_element_by_id("textarea").unwrap();


Try giving textarea the white-space: pre-wrap CSS attribute. Found this possible solution in this answer on SO.

You also might want to lookt at this section of the yew tutorial on how to use state in yew. Rather than setting the inner html of your element, if you were to use use_state, you might be able to mitigate the problem fully, by relying on yew rather than raw web API calls.

1 Like

The futures example might also be of interest. It illustrates different ways to send messages to a component, synchronously or asynchronously.

1 Like