-
Notifications
You must be signed in to change notification settings - Fork 26k
/
index.js
50 lines (44 loc) · 1.16 KB
/
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
39
40
41
42
43
44
45
46
47
48
49
50
import React from 'react'
import Link from 'next/link'
import withRedux from 'next-redux-wrapper'
import initStore from '../redux'
import CharacterInfo from '../components/CharacterInfo'
import { rootEpic } from '../redux/epics'
import * as actions from '../redux/actions'
import { of } from 'rxjs/observable/of'
class Counter extends React.Component {
static async getInitialProps ({ store, isServer }) {
const resultAction = await rootEpic(
of(actions.fetchCharacter(isServer)),
store
).toPromise() // we need to convert Observable to Promise
store.dispatch(resultAction)
return { isServer }
}
componentDidMount () {
this.props.startFetchingCharacters()
}
componentWillUnmount () {
this.props.stopFetchingCharacters()
}
render () {
return (
<div>
<h1>Index Page</h1>
<CharacterInfo />
<br />
<nav>
<Link href='/other'><a>Navigate to "/other"</a></Link>
</nav>
</div>
)
}
}
export default withRedux(
initStore,
null,
{
startFetchingCharacters: actions.startFetchingCharacters,
stopFetchingCharacters: actions.stopFetchingCharacters
},
)(Counter)