Solution 1 :

Try this and the items will be listed one after another as you expect.

incompleteFields = ["Name", "Gender", "Age"];
this.setState({incompleteFields: incompleteFields})
.inc {
  display: block;
}
<div className={classes.modalPaper}>
  <h2 id="transition-modal-title">Warning</h2>
  <br/>
  <p 
   id="transition-modal-description"
  >
    some fields are empty;
    { this.state.incompleteFields.map(incomplete => {
      return(<span className='inc'>{incomplete}</span>)
    }) }
  </p>

</div>

Solution 2 :

Nothing wrong with your code. just adding css property :

white-space:pre;

Whitespace is preserved by the browser. Text will only wrap on line breaks. Acts like the <pre> tag or p.

document.getElementById('test').innerHTML = ["Name", "Gender", "Age"].join(`n`);
#test{
  white-space:pre;
}
<div id="test"></div>

Solution 3 :

Use map function:

...

incompleteFields = ["Name", "Gender", "Age"]
this.setState({incompleteFields: incompleteFields})
...

          <div className={classes.modalPaper}>
            <h2 id="transition-modal-title">Warning</h2>
            <br/>
            <p 
             id="transition-modal-description"
            >
              some fields are empty: &#10;
              { this.state.incompleteFields && this.state.incompleteFields.map((field) => (<br/>{field})) }
            </p>
            
          </div>

Problem :

I try to pass a variable to html tag and want to display a list of strings:

...

incompleteFields = ["Name", "Gender", "Age"].join(`n`)
this.setState({incompleteFields: incompleteFields})
...

          <div className={classes.modalPaper}>
            <h2 id="transition-modal-title">Warning</h2>
            <br/>
            <p 
             id="transition-modal-description"
            >
              some fields are empty: &#10;
              { this.state.incompleteFields }
            </p>
            
          </div>

However, the following is displayed:

Warning

some fields are empty:Name Gender Age

I want to display:

Warning

some fields are empty:
Name 
Gender 
Age

Any suggestions?

Comments

Comment posted by Abin Thaha

You don’t have to insert a ‘/n’ for new line, instead map the array and display items in each line

Comment posted by CBroe

What would you use to create a line break in pure HTML …?

Comment posted by Kid_Learning_C

Is there a way to avoid creating a new .css file and putting the

Comment posted by Abin Thaha

Yeah, you can make it as div instead of span. Otherwise you can use tag

Comment posted by Kid_Learning_C

Thank you. Where exactly do I put

Comment posted by Hanna Rose

id=”transition-modal-description” . adding to this id

Comment posted by Kid_Learning_C

TypeError: this.state.incompleteFields.map is not a function

Comment posted by Kid_Learning_C

by the way, I did

Comment posted by Harshit Rastogi

You can also do

Comment posted by Hanna Rose

see my answer below

Comment posted by Kid_Learning_C

The correct way should be putting

By