Console.log shows objects that I think can be displayed with map (). However, there is an error “Nothing was returned from render. This usually means a return statement is missing. Or, to render nothing, return null.”
Where is the problem and how can I map() objects? Thanks! I export contacts.js in App.jsx:
JavaScript
x
24
24
1
export const contacts = [
2
{
3
name: "Beyonce",
4
imgURL:
5
"https://blackhistorywall.files.wordpress.com/2010/02/picture-device-independent-bitmap-119.jpg",
6
phone: "+123 456 789",
7
email: "b@beyonce.com"
8
},
9
{
10
name: "Jack Bauer",
11
imgURL:
12
"https://pbs.twimg.com/profile_images/625247595825246208/X3XLea04_400x400.jpg",
13
phone: "+987 654 321",
14
email: "jack@nowhere.com"
15
},
16
{
17
name: "Chuck Norris",
18
imgURL:
19
"https://i.pinimg.com/originals/e3/94/47/e39447de921955826b1e498ccf9a39af.png",
20
phone: "+918 372 574",
21
email: "gmail@chucknorris.com"
22
}
23
];
24
App.jsx look like:
JavaScript
1
13
13
1
import React from "react";
2
import { Card } from "./Card";
3
import { contacts } from "../contacts";
4
5
function App() {
6
contacts.map((item) => {
7
return <Card name={item.name} img={item.imgURL} phone={item.phone} email={item.email} />
8
}
9
)
10
}
11
12
export default App;
13
And Card component:
JavaScript
1
23
23
1
import React from "react";
2
3
export const Card = (props) => {
4
return (
5
<div>
6
<h1 className="heading">My Contacts</h1>
7
<div className="card">
8
<div className="top">
9
<h2 className="name">{props.name}</h2>
10
<img className="circle-img"
11
src={props.img}
12
alt="avatar_img"
13
/>
14
</div>
15
<div className="bottom">
16
<p className="info">{props.phone}</p>
17
<p className="info">{props.email}</p>
18
</div>
19
</div>
20
</div>
21
);
22
}
23
Advertisement
Answer
Add a return
statement in the App
component:
JavaScript
1
7
1
function App() {
2
return contacts.map((item) => {
3
return <Card name={item.name} img={item.imgURL} phone={item.phone} email={item.email} />
4
}
5
)
6
}
7
Notice the return
before contacts.map