Skip to content

Instantly share code, notes, and snippets.

@nofanto
Created October 5, 2020 07:08
Show Gist options
  • Save nofanto/d800388c5a323f4c629496db91402f38 to your computer and use it in GitHub Desktop.
Save nofanto/d800388c5a323f4c629496db91402f38 to your computer and use it in GitHub Desktop.
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