My problem is: when I try to change the inputs it throw customers.map is not a function. I'd like to change value and update data in the database.
//hook for fetching
const [customers, setCustomers] = useState([]);
//fetching data from db by id
useEffect(() => {
Axios.get(`http://localhost:3001/profile/${id}`)
.then((response) => {
if (response) {
setCustomers(response.data);
}
else {
alert('Error')
}
})
}, [])
And here is how I try to map, otherwise it seems like, onChange method causes the problem.
{customers.map(customer =>
<div key={customer.id}>
<div className="containerProfile">
<div className="leftInputProfile">
<p>Full Name</p>
<input type="text" name='Fullname' placeholder={!customer.Fullname && "Adja meg az adatot"}
onChange={(e) => {
setCustomers({ ...customers, [e.target.name]: e.target.value });
}}
/>
</div>
</div>
</div>
I know that, .map()
method have to get an array, but I don't know the solution here :(
response.data: