J
J
Joseph Kopeikin2017-09-11 11:54:30
React
Joseph Kopeikin, 2017-09-11 11:54:30

How to display every 3 elements in your div?

There is an array, you need to display 3 elements in each div so that the code is like this:

<div class="row">
<div>element</div>
<div>element</div>
<div>element</div>
</div>
<div class="row">
<div>element</div>
<div>element</div>
<div>element</div>
</div>

Need the easiest way to do it?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vahe, 2017-09-12
@vahe_2000

easier than that, I don't know. https://jsfiddle.net/vaheqelyan/fsc6qweh/

class App extends React.Component {
  state = { arr: ["hello", "world", "wow", "react"] };
  render() {
    return (
      <section>
        {this.state.arr.map(v => (
          <div className="row">
            <div>element</div>
            <div>element</div>
            <div>element</div>
          </div>
        ))}
      </section>
    );
  }
}

ReactDOM.render(<App />, document.body);

3897af90e101447299ec7070e16ee87c.png

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question