-1
    state = {
    size: { rows: 5, cols: 5 },
    
    bits: ['bit1', 'bit2', 'bit3', 'bit5', 'bit7'],
  };

  render() {
    return (
      <div className="badge m-3 badge-warning">
        <ul>
          {this.state.bits.map((bit) => {
            <li>{bit}</li>;
          })}
        </ul>
      </div>
    );
  }
}

This is the code I have written. My expectation was to get something like this

<div className="badge m-3 badge-warning">
   <ul>
     <li>bit1</li>
     <li>bit2</li>
     .
     .
     <li>bit7</bit>
</div>

But I got no <li> tags in between the <ul>...What is the mistake?

  • 1
    Does this answer your question? [map function not working in React](https://stackoverflow.com/questions/39999671/map-function-not-working-in-react) and [Map function not return item in render reactjs?](https://stackoverflow.com/questions/49063814) – adiga Feb 15 '21 at 05:32
  • 1
    [When should I use a return statement in ES6 arrow functions](https://stackoverflow.com/questions/28889450) – adiga Feb 15 '21 at 05:38

1 Answers1

-1

Try like this

{this.state.bits.map((item,idx) => (
    <li key={idx}> {item}</li>
)}

or

{this.state.bits.map((item, idx) => {
   return <li key={idx}>{item}</li>
}
Florin
  • 292
  • 2
  • 13