我不明白一些事情......为什么有2个请求离开?结果,出现了 2 个答案。怎么了?
这是我的代码
import {TodoItem} from "./TodoItem";
import {useEffect, useState} from "react";
import axios from "axios";
export function TodoList() {
const [allTodo, setAllTodo] = useState([]);
useEffect(() => {
axios.get(`http://127.0.0.1:8000/api/todo/`)
.then(response => {
response.data.forEach((todo) => {
setAllTodo(allTodo => [...allTodo, todo]);
})
})
.catch(error => {
console.log(error)
})
}, [])
return (
<div className="TodoList">
{
allTodo.map((todo, index) => {
return <TodoItem key={index} data={todo}/>
}
)}
</div>
);
}