-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
38 lines (32 loc) · 795 Bytes
/
index.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 { Component, render, h } from 'preact'
import Result from './Result'
import styled from 'styled-components'
const Title = styled.h1`
text-align: center;
font-family: sans-serif;
`
const SEARCH = '//api.github.com/search/repositories'
class App extends Component {
componentDidMount() {
fetch(`${SEARCH}?q=preact`)
.then(r => r.json())
.then(json => {
this.setState({
results: (json && json.items) || []
})
})
}
render(props, { results = [] }) {
return (
<div>
<Title>Example</Title>
<div className="list">
{results.map(result => <Result result={result} />)}
</div>
</div>
)
}
}
if (typeof window !== 'undefined') {
render(<App />, document.getElementById('root'))
}