customer.name.trim is not a function
TypeError: customer.name.trim is not a function
react js The code I wrote gives this error:
I have a save button that doesn’t work and gives an error like this.
The function that I wrote has been here.
const handleSaveChanges = () => {
if (editCustomer && typeof editCustomer.name === 'string') {
editCustomer.name = editCustomer.name.trim();
const updatedCustomers = customers.map(customer =>
customer.id === editCustomer.id
? { ...editCustomer }
: customer
);
onUpdateCustomers(updatedCustomers);
setSelectedCustomer(editCustomer);
setEditCustomer(null);
}
};
const handleAddCustomer = (name) => {
if (name.trim() === '') {
alert('Please enter a valid customer name');
return;
}
Emre Küçük is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
1