Sunday, 13 May 2018

javascript - Reading array elements with forEach in reactjs

I am a beginner in React. I have a pretty simple code. (There are other questions which seems to be duplicate of this but they ain't. Please read the contents also not just the question heading before marking duplicate.)



import React, { Component } from 'react';
class Likes extends Component {
render() {

var music=["linkin park", "led zaplin", "regina spector", "bruno mars"];
return(
{
music.forEach(function (value, index, array) {

{value}


})
}
);
}
}

export default Likes;


Is it correct way or should I use state. I wanted to keep it as simple as possible. But I'm getting this.(see attached image)



What is that I am missing. What else I should know.



PS: I dont have any other separate component or code. Everything is there inside the class itself.

No comments:

Post a Comment

casting - Why wasn't Tobey Maguire in The Amazing Spider-Man? - Movies & TV

In the Spider-Man franchise, Tobey Maguire is an outstanding performer as a Spider-Man and also reprised his role in the sequels Spider-Man...