-
Notifications
You must be signed in to change notification settings - Fork 0
/
App.js
34 lines (31 loc) · 926 Bytes
/
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
import React, { useState, useEffect } from 'react';
import { CardList } from './component/CardList/CardList';
import { SearchBox } from './component/SearchBox/SearchBox';
import './APP.styles.css';
function App() {
const [monsters, setMonsters] = useState([]);
const [searchField, setSearchField] = useState('');
useEffect(() => {
fetch('https://jsonplaceholder.typicode.com/users').then((response) =>
response.json().then((user) => setMonsters(user), []),
);
});
const onSearchFieldChange = (e) => {
setSearchField(e.target.value);
};
const filteredMonster = monsters.filter((monster) =>
monster.name.includes(searchField.toLowerCase()),
);
return (
<div className='App'>
<h1>MONSTER ROLODEX</h1>
<SearchBox
placeholder='search monsters'
value={searchField}
onChange={onSearchFieldChange}
/>
<CardList monsters={filteredMonster}></CardList>
</div>
);
}
export default App;