1

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

2 Answers 2

2

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(",(?=([^\']*\'[^\']*\')*[^\']*$)")]});
            })
    }
Sign up to request clarification or add additional context in comments.

12 Comments

should i refer the myTextArr to state it gives me compile error otherwise?
still not loading anything :/
it works just had to remove ...myTextArr from the setState think it made it keep reading and saving it
componentDidMount did the trick thanks man ill keep trying to improve :D
useEffect only is used in Functional Component. Let practise to learn more :))))
|
1

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

2 Comments

If you want to render a multiline text, you could just put into a <pre>{text></pre> tag and style it accordingly (or split it the way you had it and put in different spans or divs)
I will try when the text is loaded in once i figure out what the problem is! Thanks :)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.