So when a session is added and the form is submitted, I want the price of the client to be transferred into the state of my session.. that is what I am trying to do in this part of my code here.
state = {
id: null,
name: null,
duration: null,
dayOfWeek: null,
price: null
}
handleSubmit = (e) => {
e.preventDefault();
let newPrice = 0;
this.props.clientList.filter(client => {
if (client.name === this.state.name)
{newPrice = client.price}
this.setState({
price : newPrice
});
console.log("price = " + this.state.price, 'newPrice = ' + newPrice)
})
this.props.addSession(this.state);
e.target.reset();
this.setState({
id: null,
name: null,
duration: null,
dayOfWeek : null
});
}
What is happening and I am trying to portray in the image of the console and the two sessions I added is that when I add it the first time it logs out the price = null and newPrice = 40 , the second time the price = 40. Why isn't my code working here?
I can add more of my code if needed. Let me know what you need to see, thanks!