Repository navigation
Expand file tree
/
Copy pathindex.js
More file actions
65 lines (54 loc) · 1.58 KB
/
Copy pathindex.js
File metadata and controls
65 lines (54 loc) · 1.58 KB
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
56
57
58
59
60
61
62
63
64
65
import InfiniteLoader from '../src/InfiniteLoader'
import ReactDOM from 'react-dom'
import React, { Component, PropTypes } from 'react'
class TestComponent extends Component {
constructor(props) {
super(props)
this.state = { items: [] }
}
componentDidMount() {
this.loadItems()
}
loadItems() {
/* just simulating a load of more items from an api here */
setTimeout( () => {
let items = this.state.items.slice()
items = items.concat(this.getItems())
this.setState({ items: items })
}, 1000)
}
handleVisit () {
this.loadItems()
}
getItems() {
let items = []
for(var i = 0; i < 10; i++) {
items.push({ name: 'An item', description: 'A description of an item' })
}
return items
}
renderCards() {
const { items } = this.state
let cardStyle = { backgroundColor: 'white', padding: '1rem', margin: '1rem' }
const cards = items.map((item, i) => {
return (
<div key={i} style={cardStyle}>
<h3>{item.name}</h3>
<p>{item.description}</p>
</div>
)
})
return cards
}
render () {
let containerStyle = { paddingTop: '2rem', paddingBottom: '2rem', background: 'rgb(248, 245, 236)', position: 'relative' }
let visitStyle = { position: 'absolute', width: '100%', bottom: '10rem', height: '10rem' }
return (
<div style={containerStyle}>
{ this.renderCards() }
<InfiniteLoader visitStyle={visitStyle} onVisited={ () => this.handleVisit() } />
</div>
)
}
}
ReactDOM.render(<TestComponent />, document.getElementById('root'))