0

I have an Object of node in which there is an array of text i want to print node.text with line break in mapping function

   {this.state.nodes.map((node, index) => {

         return(
          <div
                 key={index}
                 className={'node ' + node.className}
                 id={node.id}
                 ref={nodes => this.refs.nodes[index] = nodes}
                 style={node.style}
                 onClick={this.activeElem}

             >

         {node.text}

        })}

it is printing an entire object i have tried \n and
both are not working how can i show it with LineBreak

This is mine Json object

here is the screenshot of my json object

https://gyazo.com/8da374e8cbdaf85c7516b27c415eab9c

3 Answers 3

1

Could you please try this {node.text}<br/> or insert it inside div element <div>{node.text}</div>

if you need to linebreak the content of the array you can do the following :

 {node.text.map(item => (
              <div >
                 {item}
              </div>
            ))}
Sign up to request clarification or add additional context in comments.

Comments

0

You could wrap your div in a React Fragment and put a <br> after every div.

Comments

0

In HTML you can't make Line Breaks via \n. There are serveral ways to do line breaks with HTML and CSS, the easiest one is the <br> tag

https://developer.mozilla.org/en-US/docs/Web/HTML/Element/br

You could map over the array and add an
tag on every iteration.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.