-
Notifications
You must be signed in to change notification settings - Fork 0
/
App.js
43 lines (37 loc) · 1.08 KB
/
App.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
import React, { Component } from 'react';
import './App.css';
import { CardList } from './components/card-list/card-list.component';
import { SearchBox} from './components/search-box/search-box.component';
// only component, not function, has access to state?
class App extends Component {
constructor() {
super();
this.state = {
monsters: [],
searchField: ''
};
}
componentDidMount() {
fetch('https://jsonplaceholder.typicode.com/users')
.then(response => response.json())
.then(users => this.setState({monsters: users}));
}
searchHandler = (keyword) => {
this.setState({searchField: keyword});
}
render() {
const { monsters, searchField } = this.state;
const found = monsters.filter(monster => monster.name.toLowerCase().includes(searchField.toLowerCase()));
return (
<div className="App">
<h1>Monsters Rolodex</h1>
<SearchBox
placeholder='search monsters'
searchHandler={this.searchHandler}
/>
<CardList monsters={found} />
</div>
);
}
}
export default App;