Jerry
Jerry

Reputation: 23

Text wont load but it reads the txt file

Hey I am trying to get the textfile inside of the jsx(html)render function. I have made the function handleText which reads the text, and just splits the text up. I can see it in the console log but when i for example try to map it or just insert the myTextArr into render it gives me an empty element for instance a paragraph with no content.

I tried using the map function but without luck so now I just inserted the array inside a p tag but it wont even show there it only loads the p tag

Upvotes: 1

Views: 54

Answers (2)

Viet Dinh
Viet Dinh

Reputation: 1951

you may try with setState to re-render you text array:

   handleText =()=>{
        fetch(text)
            .then((r)=>r.text())
            .then(text => {
                this.setState({myTextArr: [...this.state.myTextArr, text.split(",(?=([^\']*\'[^\']*\')*[^\']*$)")]});
            })
    }

Upvotes: 2

Didier Prophete
Didier Prophete

Reputation: 2031

Put your text inside a <span>{text}</span> instead of <text>{text}</text>

Upvotes: 1

Related Questions