-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.js
55 lines (49 loc) · 1.52 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
44
45
46
47
48
49
50
51
52
53
54
55
import React, {Component} from 'react';
import CardList from '../components/CardList';
import SearchBox from '../components/SearchBox.js';
import Scroll from '../components/Scroll';
// import { robots } from './robots';
import { render } from '@testing-library/react';
import './App.css';
import ErrorBoundry from '../components/ErrorBoundry.';
class App extends Component{
constructor() {
super()
this.state = {
robots: [],
searchField: ''
}
}
componentDidMount() {
debugger;
fetch('https://jsonplaceholder.typicode.com/users')
.then(response=> {
return response.json();
})
.then(users => {
this.setState({ robots: users })
});
}
onSearchChange = (event) => {
this.setState({searchField: event.target.value})
}
render() {
const {robots, searchField} = this.state;
const filteredRobots = robots.filter(robots => {
return robots.name.toLowerCase().includes(searchField.toLowerCase());
})
return !robots.length ?
<h1>Loading</h1>:
(
<div className='tc'>
<h1 className='f1'>RoboFriends</h1>
<SearchBox searchChange={this.onSearchChange}/>
<Scroll>
<ErrorBoundry>
<CardList robots={filteredRobots}/>
</ErrorBoundry>
</Scroll>
</div>
)};
}
export default App;