I know something is wrong here but I can't see it. In the code below, the event handler for the input box is working correctly, but something is wrong with the code for the save. When I click the button, I can see the event handler firing and then the whole app resets. Any ideas?
import React, { Component } from 'react';
import InputForm from './InputForm';
class Parent extends Component {
constructor(props){
super(props);
this.state = {
value: ""
};
}
inputSavedHandler = (event) => {
console.log("input saved-------------------");
}
inputChangedHandler = (event) => {
this.setState({value: event.target.value});
}
render(){
return(
<div>
<InputForm
value={this.state.value}
changed={this.inputChangedHandler}
saved={this.inputSavedHandler}
/>
</div>
);
}
}
export default Parent;
import React, { Component } from 'react';
class InputForm extends Component {
render(){
return(
<div>
<form onSubmit={this.props.saved}>
<input type="text" className="input" value={this.props.value} onChange={this.props.changed} />
<input type="submit" value="Add" />
</form>
</div>
);
}
}
export default InputForm;