I have a customers
array in state
state = {
clearable: true,
addItem: {
name: '',
age: '',
customers: [{ name: '', total: 0, prices: 0 }]
}
Now in my function below, i am setting states to the array customer but then, it keeps giving the default values when i console after setting states.
function handleCustomer(event) {
let customer_details = [...this.state.addItem.customers]
this.setState({
price: event.target.value,
total: event.target.value * event.target.value
},
() => {
customer_details.push({
name: 'Customer',
price: this.state.price,
total: this.state.total,
})
this.setState({ customer_details });
});
}
When i console this array customer, i keep getting the default value. How can i set states the new values for the array customer.
What could i be doing wrong please?
PS: I have had ideas from other solutions but i am not seeing any error in the code above