import React, {useState, useEffect, useContext} from 'react'
import AuthContext from '../context/AuthContext'
const HomePage = () => {
const [note,setNote] = useState([])
let {authTokens} = useContext(AuthContext)
useEffect(()=>{
getNotes()
},[])
let getNotes = async () => {
let response = await fetch("http://127.0.0.1:8000/api/notes",{
method:"GET",
headers:{
"Content-type":"application/json",
"Authorization":"Bearer "+String(authTokens.access)
}
})
let data =await response.json();
console.log("data i have been wait",data)
console.log("Data in it",note)
}
return (
<div>
<p>You are logged in to home paage</p>
{/* {notes.map(note =>{
<li >{note.body}</li>
})} */}
</div>
)
}
export default HomePage
我从django后端获取数据,并尝试使用map在react中显示,但它没有映射。
我可以获取数据,但当我试图设置笔记(数据)时,它不起作用。
有时它可以工作,但仍然无法绘制地图。我无法刷新map func并在其上添加数据
我没有发现任何错误。[console.log like that][1]
console.log("data i have been wait",data)
setNote(data)
console.log("Data in it",note)```
[1]: https://i.stack.imgur.com/h17QF.png