Created
October 5, 2020 07:08
-
-
Save nofanto/d800388c5a323f4c629496db91402f38 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { Component } from 'react'; | |
import Table from './Table'; | |
import Form from './Form'; | |
class App extends Component { | |
state = { | |
characters: [] | |
}; | |
removeCharacter = index => { | |
const { characters } = this.state; | |
this.setState({ | |
characters: characters.filter((character, i) => { | |
return i !== index; | |
}) | |
}); | |
} | |
handleSubmit = character => { | |
this.setState({characters: [...this.state.characters, character]}); | |
} | |
formInput = Form({handleSubmit: this.handleSubmit}); | |
render() { | |
const { characters } = this.state; | |
return ( | |
<div className="container"> | |
<h1>React Tutorial</h1> | |
<p>Add a character with a name and a job to the table.</p> | |
<Table | |
characterData={characters} | |
removeCharacter={this.removeCharacter} | |
/> | |
<h3>Add New</h3> | |
{this.formInput} | |
</div> | |
); | |
} | |
} | |
export default App; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment