I am new to React js and learnt developing static websites very quickly. Since i was a huge fan of python i have developed my backend using Django-rest-framework.
i am successfully fetching my data from backend with react front end.
how ever i always like to work with functional components than state components. i know i need to map my state object inorder to display contents in it but it is raising an error
TypeError: users.map is not a function
i don't know why and please guide me through this. one important thing is i am perfectly logging my data to console but not inside return().
the following is my code
import React,{useState,useEffect} from "react"
import{useHttpClient} from './components/http-hook'
const App=()=>{
const[users,setuser]=useState({})
const{isLoading,error,sendRequest,clearError}=useHttpClient()
useEffect(() => {
const fetchUsers=async()=>{
try{
const responseData=await sendRequest("http://127.0.0.1:8000/backend/list/")
setuser(responseData)
}
catch(err){console.log(err)}
}
fetchUsers()
}, [sendRequest])
const fetchUserslist=async=>{
console.log(users)
}
return(<div>
<button onClick={fetchUserslist}>See list</button>
<ul>
{users.map(user=><div>{user.name}</div>)}
</ul>
</div>
)
}
export default App
i have created my own custom hook useHttpClient to handle data and no complaints about it