React equivalent for ng-repeat


I am new to React.js. I am trying to bind data arrays. I am looking for the equivalent of ng-repeat, but i can't find it inside documentation.


var data =  ['red', 'green', 'blue']

using angular i would have done something like this in my html:

<div ng-repeat="i in data">{{i}}</div>

I am wondering the React's markup to do this

Problem courtesy of: Morrisda


In React, you just write the necessary JavaScript (and potentially build it into a reusable control as you'll see). It's very prescriptive and easy to do once you learn the basic patterns (and how they differ from AngularJS).

So, in the render function, you'd need to iterate through the list. In the example below, I've used map, but you could use other iterators as needed.

var List = React.createClass({
    render: function() {
        return (<div>
        { {
                return <div>{item}</div>

var data =  ['red', 'green', 'blue'];

React.render(<List data={ data }  />, document.body);

Here it is in use.

And, as you can see, you can quickly build a reusable component that can "repeat" through the list.

Solution courtesy of: WiredPrairie


To perform the same task as ng-repeat in React you just need to think natively. Under the hood ng-repeat is just using a native Javascript iterator. You can use the same sort of native iterator directly in React. For example, I`ll use

var RepeatModule = React.createClass({
  getInitialState: function() {
    return { items: [] } 
  render: function() {

    var listItems = {
      return (
        <li key={}> 
          <a href={}>{}</a> 

    return (

I got the above example from . The site has more examples of React equivaents to Angular directives.

Discussion courtesy of: Michael Martin

In your render function inside a react component you can do this:

var data =  ['red', 'green', 'blue'];
var dataComponent = [];
data.forEach(function (dataValue) {
    dataComponent.push(<div> {dataValue} </div>);

And now you can return the dataComponent.

Discussion courtesy of: Michel Uncini

Here is a real world example of this taken from real code of mine:

class Question extends Component {
    render() {
    var that = this; // Funny way to be able to access this from inside our iterator() function below.
    var iterator ={
            return (
                <div >
                            <input type= {that.props.questionType} name={that.props.questionID} value={choice}/>
                            &nbsp; {choice}


return (

            <div className="row">
                <div className="form-group col-md-12 well">
                    <h3>Question {this.props.questionID}: {this.props.questionText}:</h3>




Discussion courtesy of: Projenix

Here is an example using ES6, and a stateless component.

The below code demonstrates creating a menu by looping through a list of menu items.

import React from 'react';
import Menu from 'material-ui/lib/menus/menu';
import MenuItem from 'material-ui/lib/menus/menu-item';

const menuItems = [
    {route: '/questions', text: 'Questions'},
    {route: '/jobs', text: 'Jobs'},
    {route: '/tags', text: 'Tags'},
    {route: '/users', text: 'Users'},
    {route: '/badges', text: 'Badges'}
    {route: '/questions/new', text: 'Ask Question'}

].map((item, index) => <MenuItem key={index} primaryText={item.text} value={item.route} />);

const Sidebar = ({history}) => (
        onItemTouchTap={(e, child) => history.push(child.props.value)}

export default Sidebar;

Basically what we're doing is just pure javascript iteration utilizing

Discussion courtesy of: Kirill Fuchs

Should just be:

{ => <div>{i}</div>)}
Discussion courtesy of: Jim Bolla

This recipe can be found in it's original form on Stack Over Flow.