reset state after submit

This commit is contained in:
Max 2020-07-06 11:21:57 +02:00
parent f6454ab599
commit 0fd900acb6
2 changed files with 5 additions and 1 deletions

View File

@ -23,6 +23,10 @@ class AddPlant extends React.Component{
handleSubmit = (e) => {
e.preventDefault();
//console.log(this.state)
this.setState({ // reset state
name: '',
type: ''
})
this.props.addPlant(this.state)
}

View File

@ -16,7 +16,7 @@ class Settings extends React.Component{
// pass this function to the addplant comp as a prop
addPlant = (plant) => {
plant.id = this.state.plants.length + 1 // TODO rework
console.log(plant.id)
let plants = [...this.state.plants, plant]; // create a copy of the array and add the new plant to it
this.setState({