我正在從我的 api 獲取一些數據。在獲取數據的回調中,數據是一個數組:const classes = useStyles();const [posts, setPosts] = useState([]);useEffect(() => { fetch('https://forum-temp.herokuapp.com/api/posts') .then((res) => res.json()) .then((res) => { console.log(typeof res.data.docs) // Array setPosts(res.data.docs); });}, []); 在我的功能組件的 return 語句內 -<div className="post__container"> { {posts.map((post, i) => ( <MiniPost dp="https://picsum.photos/200" username="blah" time="blah" heading="blah" comments="4" history={history} key={i} /> ))} } </div>
當存儲在反應狀態中時,數組變成對象
肥皂起泡泡
2023-08-18 16:29:37