# React Hooks - trying to map data into component

**URL:** <https://forum.freecodecamp.org/t/react-hooks-trying-to-map-data-into-component/333566>\
**Category:** General\
**Created:** [December 16, 2019, 5:27am UTC](https://forum.freecodecamp.org/t/react-hooks-trying-to-map-data-into-component/333566 "2019-12-16T05:27:36Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![ainneo](https://avatars.discourse-cdn.com/v4/letter/a/9f8e36/32.png) [@ainneo](https://forum.freecodecamp.org/u/ainneo)\
**Post date:** [December 16, 2019, 5:27am UTC](https://forum.freecodecamp.org/t/react-hooks-trying-to-map-data-into-component/333566/1 "2019-12-16T05:27:36Z")

</div>

my data is not mapping into component. “error message is: TypeError: Cannot read property ‘map’ of undefined”

code below:

```auto
import React, { useEffect, useState } from 'react';
import { getNews } from '../news-api';
import NewsCard from "./NewsCard.js";

function NewsContainer() {

const [news, setNews] = useState([]);
useEffect(()=>{ getNews().then(data=>setNews(data));
},[]);
return news.map(article => <NewsCard props={article} />
)
}

export default NewsContainer

```

---

<div class="post-metadata">

**Author:** ![Gilbert1391](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/gilbert1391/32/93761_2.png) [@Gilbert1391](https://forum.freecodecamp.org/u/Gilbert1391)\
**Post date:** [December 16, 2019, 4:21pm UTC](https://forum.freecodecamp.org/t/react-hooks-trying-to-map-data-into-component/333566/2 "2019-12-16T16:21:31Z")

</div>

What does `getNews()` return? Try logging in in the console.

---

<div class="post-metadata">

**Author:** ![ainneo](https://avatars.discourse-cdn.com/v4/letter/a/9f8e36/32.png) [@ainneo](https://forum.freecodecamp.org/u/ainneo)\
**Post date:** [December 18, 2019, 9:03pm UTC](https://forum.freecodecamp.org/t/react-hooks-trying-to-map-data-into-component/333566/3 "2019-12-18T21:03:28Z")

</div>

I finally figured it out. I acutally wrote forgot to add articles in the request for data.

---

<div class="post-metadata">

**Author:** ![ILM](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/ilm/32/363239_2.png) [@ILM](https://forum.freecodecamp.org/u/ILM)\
**Post date:** [January 16, 2021, 11:29am UTC](https://forum.freecodecamp.org/t/react-hooks-trying-to-map-data-into-component/333566/4 "2021-01-16T11:29:59Z")

</div>

Closed on January 16, 2021, 11:29am UTC


