// REACT:
import {React, useState, useEffect} from 'react'
// HOME:
export default function News() {
const [nyseData, setNyseData] = useState([])
const [isLoading, setIsLoading] = useState(true)
useEffect(() => {
fetch(`https://catfact.ninja/facts?max_length=30&limit=10`)
.then(res => res.json())
.then(data => {
setNyseData(data)
setIsLoading(false)
});
}, [])
console.log('State Data:', nyseData.data)
// console.log(nyseData);
// {nyseData.data[0].fact}
return (
<>
<div>
{/* {isLoading ? <h1>loading...</h1> : <h1>{nyseData.data[0].fact}</h1>} */}
{isLoading ? <h1>loading...</h1> :
<div>
{nyseData.map((x) => {
return (
<div>
<h1>{x.fact}</h1>
</div>
)
})}
</div>}
</div>
</>
1.) the img attached is the data I am working with logged in chrome tools 2.) I want to point out that the line below the first div with the ternary statement with isLoading works fine. I am able to access object data (fact or length) within my state array value. 3.) My issue: I want to map all the facts ( or length’s) from each object in array to the page. When trying to do this it gives me a map is not a function error. I have tried multiple ways but have had no luck in solving this. I also followed this youtube video at minute 4:13 which appears to be close to identical to what I have (Using Map Method in React - Mapping through the state, API, JSON Data - YouTube) including this article (TypeError: map() is not a function in React | bobbyhadz) but still nowhere. Can someone help? I tried asking on stack overflow here () but I am not sure what this person is telling me since I already have chosen one, which is [nyseData, setNyseData] = useState()