How do I map out the data I've put in my console/state? I've been trying to add a map function where I left the "//m", and it seems like it should be simple enough but I can't seem to do it properly.
import React, { useState, useEffect } from "react";
import axios from "axios";
import EmployeeDetail from "./EmployeeDetail";
function App() {
const [employees, setEmployees] = useState([]);
const [loading, setLoading] = useState(false);
useEffect(() => {
setLoading(true);
axios.get("https://randomuser.me/api/?results=10&nat=us")
.then(res => {
console.log(res.data.results);
setEmployees(...res.data.results);
setLoading(false);
})
.catch(err => {
console.log(err);
});
}, []);
return (
<div className="App">
<h1>Employee List</h1>
//m
</div>
);
}
export default App;
I was able to make it using the API the guy in the youtube video I referenced used ("https://restcountries.eu/rest/v2/all") with the following function:
{countries.map((country) => (
<div key={country.name}>
{country.name} - {country-capital}
</div>
))}
I'm just having problems with doing it with my own API.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…