Thursday, May 9, 2024
 Popular · Latest · Hot · Upcoming
6
rated 0 times [  10] [ 4]  / answers: 1 / hits: 16681  / 6 Years ago, thu, september 20, 2018, 12:00:00

this is my code:



import React, { Component } from react;
import Person from ./Person/Person;

class Persons extends Component {
render() {
this.props.persons.map((person, index) => {
return (
<div>
<Person
click={() => this.props.clicked(index)}
name={person.name}
age={person.age}
key={person.id}
changed={event => this.props.changed(event, person.id)}
/>
</div>
);
});
}
}

export default Persons;

More From » reactjs

 Answers
30

In a React component you need to return your JSX. If this is a functional one it is simply like this:



function Component() {
return <div>Some JSX</div>;
}


If it is a class component, your render method should return some JSX.



class Component extends React.Component {
render() { return <div>Some JSX</div>; }
}


Your code has only one return and this is for your map. So, put your code inside a top return.



import React, { Component } from react;
import Person from ./Person/Person;

class Persons extends Component {
render() {
return (
<div>
{this.props.persons.map((person, index) => {
return (
<div>
<Person
click={() => this.props.clicked(index)}
name={person.name}
age={person.age}
key={person.id}
changed={event => this.props.changed(event, person.id)}
/>
</div>
);
})}
</div>
);
}
}

export default Persons;

[#53451] Monday, September 17, 2018, 6 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
wilson

Total Points: 27
Total Questions: 93
Total Answers: 93

Location: Tajikistan
Member since Sun, Aug 29, 2021
3 Years ago
wilson questions
Tue, Aug 9, 22, 00:00, 2 Years ago
Wed, May 11, 22, 00:00, 2 Years ago
Wed, May 20, 20, 00:00, 4 Years ago
Wed, May 13, 20, 00:00, 4 Years ago
;