Answer the question
In order to leave comments, you need to log in
What does this React.js code do?
Hello everyone, I started to study React, my nose was pushed with this code
var News = React.createClass({
render: function() {
var data = this.props.data;
var newsTemplate = data.map(function(item, index) {
return (
<div key={index}>
<p className="news__author">{item.author}:</p>
<p className="news__text">{item.text}</p>
</div>
)
})
return (
<div className="news">
{newsTemplate}
</div>
);
}
});
Answer the question
In order to leave comments, you need to log in
As copal answered , you really need to close the knowledge gaps in js itself. And then read the react tutorial.
Try in the render component, make console.log(this.props)
-> there will be an object, with the data key. That's why we write this.props.data.
About map . (as it is written there - The function that creates an element in a new array takes three arguments, just the first two are the "current element" and "index"
ps tutorial chose a good one :) , but you need to increase the level of basic JS, it will be better for learning.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question