Last active
August 9, 2019 06:13
-
-
Save harrisonmalone/dafc312aab366604ce076d27827c7dde to your computer and use it in GitHub Desktop.
This file contains hidden or 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 from 'react'; | |
| import './App.css'; | |
| import * as historyData from './history.json'; | |
| // import Event from './Event' | |
| class App extends React.Component { | |
| state = { | |
| events: historyData.result.events | |
| } | |
| search = (event) => { | |
| event.preventDefault() | |
| const query = event.target.parentElement.children[0].value | |
| console.log(this.state.events) | |
| // 1. create a filtered list (array) based on the search query, using the .filter method on this.state.events, .includes on the description string | |
| // 2. setState to be the filtered list | |
| // 3. render the filtered array in render | |
| } | |
| render() { | |
| const centerHeading = { | |
| textAlign: 'center', | |
| color: 'red' | |
| } | |
| return ( | |
| <> | |
| <h1 style={centerHeading}>Search for 20th Century Events</h1> | |
| <form> | |
| <input type="text" name="search" id="search"/> | |
| <input onClick={this.search} type="submit" value="Submit" id="submit" /> | |
| </form> | |
| </> | |
| ); | |
| } | |
| } | |
| // stateful component | |
| // class, like object orientated in python | |
| // using render(), which is a lifecycle method, kind of like an instance method in python | |
| export default App; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment