I am not sure if I am mistaken about the asynchronous or React itself.
const fetchData = async () => {
const response = await sessionApi.get("/sessions", {
headers: {
Authorization: user.user?.token
}
})
if (response.data.success) {
setSessionData(response.data.message)
console.log(sessionData)
}
}
this is my fetchData.I try using async in function when I console.log to show data it show empty [] if I change to
console.log(response.data.message)
It shows my data from request.So that my api is not wasted.
useEffect(() => {
fetchData()
console.log(sessionData)
}, [])
Ok then I use useEffect in my React web then I console.log(sessionData) but it still empty list
const [sessionData, setSessionData] = useState([])
that is my my state. Maybe I am mistaken. Please tell me where I missed.