/
page.js
38 lines (32 loc) · 848 Bytes
/
page.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
import React, { Component } from 'react'
import Pokemon from '../components/pokemon'
import Search from '../components/search'
class Page extends Component {
componentDidMount() {
this.props.fetchPokemons()
}
handleSearch(event) {
this.props.filterPokemons(event.currentTarget.value)
}
render() {
let { displayedPokemons, isFetched } = this.props.page
let pokemons = displayedPokemons.map(pokemon => {
return (
<li className="pokemons__item" key={pokemon.id}>
<Pokemon pokemon={pokemon} />
</li>
)
})
return (
<div className="page">
<Search onChange={this.handleSearch.bind(this)} />
{isFetched ? (
<p>Loading...</p>
) : (
<ul className="pokemons">{pokemons}</ul>
)}
</div>
)
}
}
export default Page