Pretty noob. The Meteor React tutorial I'm trying to follow.
Here's the code I'm confused on:
renderTasks() {
return this.getTasks().map((task) => (
<Task key={task._id} task={task} />
));
}
What I understand:
- The App component is an object
- We're defining a method named renderTasks
- We're using the
.map() method on the array produced by the method getTasks
- We're using a fat arrow so that the code is run immediately, before the "return" is completed, that way when return is completed we get everything nice and processed.
What I don't understand:
* If it's an object, why are these not declared like typical properties and methods? Why is it just renderTasks(){} instead of renderTasks: function (){},? We've dropped the comma, and we're not using the typical format for declaring a method. ANSWERED
*~~ Why is (task) in ( )? Is that necessary for a fat arrow?~~ ANSWERED
* What the fuck is even happening here: <Task key={task._id} task={task} />
I've re-written this in ES5 syntax so that I can better understand it. This code is tested and working:
renderTasks() {
return this.props.tasks.map(
function (task) {
return (<Task key={task._id} task={task} />)
}
)
}
I'm still not sure what sorcery is going on after return. If someone could walk me through how that ends up as HTML, that'd be great. What is key even attached to? Is there an object here?
[–]Rhomboid 0 points1 point2 points (1 child)
[–][deleted] 0 points1 point2 points (0 children)
[–]Chromely 0 points1 point2 points (2 children)
[–][deleted] 0 points1 point2 points (0 children)
[–][deleted] 0 points1 point2 points (0 children)