reset state after submit
This commit is contained in:
parent
f6454ab599
commit
0fd900acb6
@ -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)
|
||||
}
|
||||
|
||||
|
||||
@ -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({
|
||||
|
||||
Loading…
Reference in New Issue
Block a user