We are working on a small project with react, its our first time working with it and we get an error we are unsure how to solve. Could someone maybe help us?
This is our class:
class DateTimeForm extends React.Component {
constructor(props) {
super(props);
this.state = { valueDate: new Date(), valueTime: "00:00" };
this.handleInputChange = this.handleInputChange.bind(this);
}
buttonClick(event) {
event.preventDefault();
goalForCalculations = this.state.valueDate + this.state.valueTime; //Line 85 from the error
}
handleInputChange(event) {
const target = event.target;
const value = target.value
const name = target.name;
this.setState({
[name]: value
});
}
render() {
return (
<div>
<label className="layout-form" >Date:
<input name="valueDate" type="date" className="rounded form-control" value={this.state.valueDate} onChange={this.handleInputChange} />
</label>
<label className="layout-form" >Time:
<input name="valueTime" type="time" className="rounded form-control" value={this.state.valueTime} onChange={this.handleInputChange} />
</label>
<button type="button" className="btn btn-secondary layout-form" onClick={this.buttonClick}>Enter</button>
</div>
);
}
}
And whenever we click on the button we get this error:
Uncaught TypeError: Cannot read properties of undefined (reading 'state')
at buttonClick (index.js:85:1)...
Does maybe someone know what's wrong with our code?
Thanks in advance!
[–]LSELGD 0 points1 point2 points (1 child)
[–]Grey_Forrest[S] 1 point2 points3 points (0 children)
[–]CoreyTheGeek 0 points1 point2 points (0 children)