我无法将数据复制设置为元素我在这里做错了什么?我是react的新手。这是一个json
import React, { useEffect, useState } from 'react';
import './App.css';
import axios from 'axios';
function App() {
const [elements, setElements] = useState([]);
useEffect(() => {
const res = async () => {
const result = await axios.get('/data');
const data = result.data;
setElements(elements => [...elements, data]);
};
res();
}, []);
console.log(elements.map(element => console.log(element)));
return (
<div className='App'>
Hello
{elements.map(element => (
<div key={element._id}>{element.name}</div>
))}
</div>
);
}
export default App;