i am fetchin details from database wanted to display that into the table, but for initial purpose i wanted to just display on browser without table and stuff.. am getting values.map is not a function but i could the see values printed in console
here iam using function component
export default function SimpleTable() {
const [values, setValues] = useState({});
here is the fetch function
async function handleTable(){
const res = await fetch("http://localhost:4000/productslist")
const data = await res.json()
setValues(data.data)
console.log(data.data)
}
calling the fetch function on useEffect
useEffect(()=>{
handleTable()
},[])
Rendering the values into browser
return (
<div>
{console.log(values)}
{values.map(v => {
return <h4 key={v.idaddproducts}>{v.productName}{v.productId}{v.productBrand}</h4>})}
</div>
);
}
here is the error
Uncaught TypeError: values.map is not a function