whenever i try to fetch the data with .map function is show me the error
user.map is not a function
I use the below code for fetching the data
user.map((user,index) => <>
<h1> {user.name} </h1>
<h1> {user.address} </h1>
</>)
And use the below code for getting the data from backend,
const [user, setUser] = useState([
{
name:'',
phone:'',
bgroup:'',
pincode:'',
address:''
}
]);
useEffect(() => {
fetch("/Donate").then(res=>{
if(res.ok){
return res.json();
}
}).then(jasonRes=>setUser(jasonRes));
},[])
With this , i get data in console , when i use the below code
console.log(user)
const [user, setUser] = useState([]);
useEffect(() => {
fetch("/Donate").then(res=>{
if(res.ok){
return res.json();
}
}).then(jasonRes=>setUser(jasonRes && jasonRes.Donate));
},[])
return (
<>
{user.map((el, i)=> {
<div key={i}>
<h1> {el.name} </h1>
<h1> {el.address} </h1>
</div>
})}
</>
)