Heres my app structure
Codepen Example : https://codesandbox.io/s/awesome-blackwell-kd3nn
class MasterForm extends Component {
constructor() {
super();
this.state = {
userInput: "",
available: "",
silos: []
};
}
handleFormSubmit = e => {
e.preventDefault();
this.silo_1Lookup();
};
handleInputChange = e => {
let input = e.target;
let name = e.target.name;
let value = input.value;
this.setState({
[name]: value
});
};
silo_1Lookup = () => {
let silos = [...this.state.silos];
silos.push({
userInput: this.state.userInput,
available: this.state.available
});
this.setState({
silos,
userInput: "",
available: ""
});
const siloDepthFilling = {
"0": "926",
"0.5": "893",
"1": "860",
"1.5": "827",
"2": "794",
"2.5": "761",
"3": "728",
"3.5": "695",
"4": "662",
"4.5": "629",
"5": "595"
};
console.log("function ran");
return siloDepthFilling[silos[0].userInput];
};
}
I'm trying to change the property of silos[0].available to match the content inside of my silo_1Lookup() function.
For example, if the user enters 5, silos[0].available should be set to "595"
if (silos[0].userInput === '5') {
return silos[0].available = "595"
}
kinda like that but using the dictionary inside silo_1Lookup();
At the moment, the function runs, but silos[0].available is not being updated with a new value, and there is no error message

setState()after callingsilo_1Lookup().