-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
46 lines (39 loc) · 1.07 KB
/
script.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import React, { Component } from "react"
import { CardList } from "./components/card-list/card-list.component"
import { SearchBox } from "./components/search-box/search-box.component"
import "./App.css"
//TODO:
class App extends Component {
constructor() {
super()
this.state = {
monsters: [],
searchField: ""
}
}
componentDidMount() {
fetch("http://jsonplaceholder.typicode.com/users")
.then(response => response.json())
.then(users => this.setState({ monsters: users }))
}
handleChange = e => {
this.setState({ searchField: e.target.value })
}
render() {
const { monsters, searchField } = this.state
const filteredMonsters = monsters.filter(monster =>
monster.name.toLowerCase().includes(searchField.toLowerCase())
)
return (
<div className="App">
<h1>Monster Rolodex </h1>
<SearchBox
placeholder="search monsters"
handleChange={this.handleChange}
/>
<CardList monsters={filteredMonsters}></CardList>
</div>
)
}
}
export default App