Reputation: 23
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
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
Reputation: 2031
Put your text inside a <span>{text}</span>
instead of <text>{text}</text>
Upvotes: 1