0

http://codepen.io/naveennsit/pen/oxRwYM

HI I am trying to display data of array in list. I am getting undefined error why ?

here is my code http://codepen.io/naveennsit/pen/oxRwYM

var stations = [
  {call:'station one',frequency:'000'},
  {call:'station two',frequency:'001'}
]; 
class App extends React.Component {

  render (){
    var stationComponents = this.props.name.map(function(station) {
            return <div className="station">{station.call}</div>;
        });
        return <div>{stationComponents}</div>;
  }
   handleClick(e){
     alert('--')
   } 

}


React.render(<App name='{stations}'>ssssss</App>,document.getElementById('app'))
2
  • 1
    Remove ', should be <App name={ stations }>ssssss</App> Commented May 17, 2016 at 10:15
  • thanks got the solutuion ..any react js good tutorial Commented May 17, 2016 at 10:17

1 Answer 1

1

You shouldn't wrap props in quotes, as that turns them into a string literal. You're getting an undefined error because you're effectively trying to call map() on the string "{stations}", rather than your stations object.

Replace <App name='{stations}'>ssssss</App> with <App name={stations}>ssssss</App>.

Sign up to request clarification or add additional context in comments.

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.